I am trying to call a const overload function
void process(std::map<std::string,std::shared_ptr<const Data_Struct>>);
with data I generate. Because I generate the data, I use a non-const version
std::map<std::string,std::shared_ptr<Data_Struct>> my_data;
When I try to call my function with
process(my_data);
I get the error:
error C2664: 'void process(std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>)' : cannot convert argument 1 from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
I have tried a variety of casting variations but all fail to do the job. Any help is appreciated.
Here is my test code with the casting variants and associated error codes (I am using Visual C++ community edition 2013):
struct Data_Struct
{
int a;
std::string b;
};
void process(std::map<std::string,std::shared_ptr<const Data_Struct>>);
void calling_function() {
std::map<std::string,std::shared_ptr<Data_Struct>> my_data;
my_data.emplace("test",std::shared_ptr<Data_Struct>(new Data_Struct)).first->second->a = 2;
process(my_data);
// error C2664: 'void process(std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>)' : cannot convert argument 1 from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(std::map<std::string,std::shared_ptr<const Data_Struct>>(my_data));
// error C2440: '<function-style-cast>' : cannot convert from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process((std::map<std::string,std::shared_ptr<const Data_Struct>>)my_data);
// error C2440: 'type cast' : cannot convert from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(static_cast<std::map<std::string,std::shared_ptr<const Data_Struct>>>(my_data));
// error C2440: 'static_cast' : cannot convert from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(reinterpret_cast<std::map<std::string,std::shared_ptr<const Data_Struct>>>(my_data));
// error C2440: 'reinterpret_cast' : cannot convert from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(const_cast<std::map<std::string,std::shared_ptr<const Data_Struct>>>(my_data));
// error C2440: 'const_cast' : cannot convert from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' to 'std::map<std::string,std::shared_ptr<const Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(std::static_pointer_cast<std::map<std::string,std::shared_ptr<const Data_Struct>>>(my_data));
// error C2784: 'std::shared_ptr<_Ty> std::static_pointer_cast(const std::shared_ptr<_Ty2> &) throw()' : could not deduce template argument for 'const std::shared_ptr<_Ty2> &' from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
process(std::const_pointer_cast<std::map<std::string,std::shared_ptr<const Data_Struct>>>(my_data));
// error C2784: 'std::shared_ptr<_Ty> std::const_pointer_cast(const std::shared_ptr<_Ty2> &) throw()' : could not deduce template argument for 'const std::shared_ptr<_Ty2> &' from 'std::map<std::string,std::shared_ptr<Data_Struct>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'
}
void process(std::map<std::string,std::shared_ptr<const Data_Struct>> data) {
for(auto &d : data)
std::cout << d.first << std::endl;
}
The two map types are totally unrelated and in spite of the apparent similiarity cannot be used interchangeably. You do have a few options though:
Populate your data class in its constructor so you don't have to mutate it after creation.
Have the process function work on a templated iterator range rather than a specific container.
Have the process function work on a templated container rather than a specific type.
The function process() takes its parameter by value. This means that when it's called a copy of the map is taken, processed and then discarded. I don't know if that's your intention. Assuming it is, what you need is a conversion function:
#include <iostream>
#include <string>
#include <map>
#include <memory>
struct Data_Struct
{
int a;
std::string b;
};
void process(std::map<std::string,std::shared_ptr<const Data_Struct>>);
std::map<std::string,std::shared_ptr<const Data_Struct>>
convert_map(const std::map<std::string,std::shared_ptr<Data_Struct>>& source)
{
std::map<std::string,std::shared_ptr<const Data_Struct>> ret;
for(const auto& item : source) {
ret.emplace(item.first, item.second);
}
return ret;
}
void process(std::map<std::string,std::shared_ptr<const Data_Struct>> data) {
for(auto &d : data)
std::cout << d.first << std::endl;
}
void calling_function() {
std::map<std::string,std::shared_ptr<Data_Struct>> my_data;
my_data.emplace("test",std::shared_ptr<Data_Struct>(new Data_Struct)).first->second->a = 2;
process(convert_map(my_data));
}
using namespace std;
int main()
{
calling_function();
return 0;
}
Related
Stuff Used:
Windows 10
libpq:x64-windows 9.6.1-7
libpqxx:x64-windows 6.4.4
MSVC Compiler
My Code:
#include <pqxx/pqxx>
#include <array>
struct Hand
{
std::string GameType;
int64_t TotalSize{};
char Currency{};
int16_t MaxHeight{};
std::array<std::string, 5> Apple;
bool Foo = false;
};
int main() {
//Connect possible trycatch
pqxx::connection database_connection("dbname = blablabla user = postgres password = blablabla\
hostaddr = 127.0.0.1 port = 5432");
//Prepare Insert
database_connection.prepare("Hand_Insert", "INSERT INTO Hand(GameType, TotalSize, Currency, MaxHeight, Apple, Foo) VALUES\
VALUES($1, $2,$3, $4,$5::text[3],$6)");
Hand hand;
hand.Currency = '$';
hand.Apple.at(0) = "value1";
hand.Apple.at(1) = "value2";
hand.Apple.at(2) = "value3";
hand.Foo = true;
hand.GameType = "TestType";
hand.MaxHeight = 7;
hand.TotalSize = 300;
pqxx::work work(database_connection);
try
{
pqxx::result result = work.exec_prepared("Hand_Insert", hand.GameType, hand.TotalSize, hand.Currency, hand.MaxHeight, hand.Apple, hand.Foo);
work.commit();
}
catch (const std::exception& e) {
std::cout << e.what() << "\n";
work.abort();
}
return 0;
}
This is the Output:
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,29): error C2027: use of undefined type 'pqxx::string_traits<Arg,void>'
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,29): error C2027: with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,29): error C2027: [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,29): error C2027: Arg=char
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,29): error C2027: ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192): message : see declaration of 'pqxx::string_traits<Arg,void>'
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192): message : with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192): message : [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192): message : Arg=char
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192): message : ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : see reference to function template instantiation 'void pqxx::internal::params::add_field<char>(const Arg &)' being compiled
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : Arg=char
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : see reference to function template instantiation 'void pqxx::internal::params::add_fields<char&,int16_t&,std::array<std::string,5>&,bool&>(Arg,int16_t &,std::array<std::string,5> &,bool &)' being compiled
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : Arg=char &
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : see reference to function template instantiation 'void pqxx::internal::params::add_fields<int64_t&,char&,int16_t&,std::array<std::string,5>&,bool&>(Arg,char &,int16_t &,std::array<std::string,5> &,bool &)' being compiled
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : Arg=int64_t &
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(212): message : ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(111): message : see reference to function template instantiation 'void pqxx::internal::params::add_fields<std::string&,int64_t&,char&,int16_t&,std::array<std::string,5>&,bool&>(Arg,int64_t &,char &,int16_t &,std::array<std::string,5> &,bool &)' being compiled
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(111): message : with
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(111): message : [
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(111): message : Arg=std::string &
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(111): message : ]
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\transaction_base.hxx(397): message : see reference to function template instantiation 'pqxx::internal::params::params<std::string&,int64_t&,char&,int16_t&,std::array<std::string,5>&,bool&>(std::string &,int64_t &,char &,int16_t &,std::array<std::string,5> &,bool &)' being compiled
1>C:\Users\Vaio\source\repos\Project3\Project3\Source.cpp(42): message : see reference to function template instantiation 'pqxx::result pqxx::transaction_base::exec_prepared<std::string&,int64_t&,char&,int16_t&,std::array<std::string,5>&,bool&>(const std::string &,std::string &,int64_t &,char &,int16_t &,std::array<std::string,5> &,bool &)' being compiled
1>C:\vcpkg\vcpkg\installed\x64-windows\include\pqxx\internal\statement_parameters.hxx(192,1): error C3861: 'is_null': identifier not found
1>Done building project "Project3.vcxproj" -- FAILED.
How can I define a new C++ type conversion so that libpqxx will know how to convert that type?
Or if the error is something else anything will help!
This is a Game Engine for SFML builded in c++. I get some errors that i don't know how to fix it. If someone can solve this problem i will apriciated a lot.
I'm still learning c so por someone could same an obious problem or solucion but i just copied the code from another page and I do exactly the same and mine code isn't working
Errors:
Error C2065: 'StateSystem' : undeclared identifier
Error C2923: 'std::unique_ptr' : 'StateSystem' is not a valid template type
argument for parameter '_Ty'
Error C3203: 'unique_ptr' : unspecialized class template can't be used as a
template argument for template parameter '_Ty', expected a real type
Error C2512: 'std::unique_ptr' : no appropriate default constructor
available
Error C2780: '_OutTy *std::move(_InIt,_InIt,_OutTy (&)[_OutSize])' : expects
3 arguments - 1 provided
1> c:\program files (x86)\microsoft visual studio
12.0\vc\include\xutility(2510) : see declaration of 'std::move'
Error C2893: Failed to specialize function template
'remove_reference<_Ty>::type &&std::move(_Ty &&) throw()'
1> With the following template arguments:
1> '_Ty=Victor::StateRef &'
Error C2227: left of '->Resume' must point to class/struct/union/generic
type
1> type is 'int'
Error C2780: '_OutTy *std::move(_InIt,_InIt,_OutTy (&)[_OutSize])' : expects
3 arguments - 1 provided
1> c:\program files (x86)\microsoft visual studio
12.0\vc\include\xutility(2510) : see declaration of 'std::move'
Error C2893:
Failed to specialize function template 'remove_reference<_Ty>::type
&&std::move(_Ty &&) throw()'
1> With the following template arguments:
1> '_Ty=Victor::StateRef &'
Error C2227: left of '->Initialize' must point to class/struct/union/generic
type
1> type is 'int'
Error C2440: 'return' : cannot convert from 'int' to 'Victor::StateRef &'
And This is the code that provides errors.
State.h
#pragma once
class State
{
public:
virtual void Initialize() = 0;
virtual void HandleInput() = 0;
virtual void Update() = 0;
virtual void Draw(float DeltaTime) = 0;
virtual void Pause()
{
}
virtual void Resume()
{
}
};
StateSystem.h
#pragma once
#include <memory>
#include <stack>
#include "State.h"
typedef std::unique_ptr <StateSystem> StateRef;
class StateSystem
{
public:
StateSystem()
{
}
~StateSystem()
{
}
void AddState(StateRef newStat, bool isReplacing = true);
void RemoveState();
void ProcessStateChanges();
StateRef &GetActiveState();
private:
std::stack<StateRef> _states;
StateRef _newState;
bool _isRemoving;
bool _isAdding;
bool _isReplacing;
};
StateSystem.cpp
#include "StateSystem.h"
void StateSystem::AddState(StateRef newState, bool isRepalcing)
{
this->_isAdding = true;
this->_isReplacing = isRepalcing;
this->_newState = std::move(newState);
}
void StateSystem::RemoveState()
{
this->_isRemoving = true;
}
void StateSystem::ProcessStateChanges()
{
if (this->_isRemoving && !this->_states.empty())
{
this->_states.pop();
if (!this->_states.empty())
{
this->_states.top()->Resume();
}
this->_isRemoving = false;
}
if (this->_isAdding)
{
if (!this->_states.empty())
{
if (this->_isReplacing)
{
this->_states.pop();
}
else
{
this->_states.top()->Pause();
}
}
this->_states.push(std::move(this->_newState));
this->_states.top()->Initialize();
this->_isAdding = false;
}
}
StateRef &StateSystem::GetActiveState()
{
return this->_states.top();
}
there's no StateSystem before typedef std::unique_ptr <StateSystem> StateRef; just add class StateSystem before it.
it says it cannot find the StateSystem class. you have to declare it first like this:
class StateSystem;
typedef std::unique_ptr <StateSystem> StateRef;
class StateSystem
{
//members
};
or put your typedef after the StateSystem definition like this:
class StateSystem
{
//members
};
typedef std::unique_ptr <StateSystem> StateRef;
I have those functions in some open source lib called uWebSockets
any way I try to run its simple example using Visual Studio 2013.
The function I try to call looks like this:
template <bool isServer>
void Group<isServer>::onMessage(std::function<void (WebSocket<isServer>, char *, size_t, OpCode)> handler) {
messageHandler = handler;
}
and the example looks like this:
int main()
{
uWS::Hub h;
h.onMessage([](uWS::WebSocket<uWS::SERVER> ws, char *message, size_t length, uWS::OpCode opCode) {
ws.send(message, length, opCode);
});
h.listen(3000);
h.run();
}
The error I'm getting looks like this :
1>D:\dev\cpp\server\uWebSockets\git\uWebSockets\uWebSockets\examples\echo.cpp(9): error C2668: 'uWS::Group<false>::onMessage' : ambiguous call to overloaded function
1> d:\dev\cpp\server\uwebsockets\git\uwebsockets\uwebsockets\src\Group.h(69): could be 'void uWS::Group<false>::onMessage(std::function<void (uWS::WebSocket<false>,char *,size_t,uWS::OpCode)>)'
1> d:\dev\cpp\server\uwebsockets\git\uwebsockets\uwebsockets\src\Group.h(69): or 'void uWS::Group<true>::onMessage(std::function<void (uWS::WebSocket<true>,char *,size_t,uWS::OpCode)>)'
1> while trying to match the argument list '(main::<lambda_f789fc974d6d87c4a2444e6ded66c2a0>)'
Question:
Can I over come the error without upgrading the Visual Studio to 2015?
or it is not related to the compiler version?
UPDATE :
if i set it to : h.onMessage<true> or h.onMessage<uWS::SERVER>
im getting :
This error :
1>D:\dev\cpp\server\uWebSockets\git\uWebSockets\uWebSockets\examples\echo.cpp(10): error C2678: binary '>' : no operator found which takes a left-hand operand of type 'bool' (or there is no acceptable conversion)
1> could be 'built-in C++ operator>(void (__cdecl *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__cdecl *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__stdcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__stdcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__fastcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__fastcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> or 'built-in C++ operator>(void (__vectorcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode), void (__vectorcall *)(uWS::WebSocket<true>,char *,size_t,uWS::OpCode))'
1> while trying to match the argument list '(bool, main::<lambda_f789fc974d6d87c4a2444e6ded66c2a0>)'
I got the same errors, after minor fix I got it running:
int main()
{ uWS::Hub h;
h.onMessage([](uWS::WebSocket<uWS::SERVER>* ws, char *message, size_t length, uWS::OpCode opCode) {
ws->send(message, length, opCode);
});
h.listen(3000);
h.run();
}
My compiler is the latest VC++ 2013 preview. (Updated!)
#include <new>
struct A
{
A(int)
{}
};
void f(void (*fn)(void*))
{
A a(0);
fn(&a);
}
int main()
{
int n = 0;
auto fn = [&](void* p)
{
//
// error C2664: 'void f(void (__cdecl *)(void *))' :
// cannot convert parameter 1 from
// 'main::<lambda_b20f735b061d78dbb0f2f653ecbb482f>'
// to 'void (__cdecl *)(void *)'
//
new (p) A(n);
};
f(fn);
}
Why is this usage not allowed?
Is this behavior defined by the standard? If yes, what's the rationale?
void f(void (*fn)(void*))
takes a function pointer, not a lambda.
auto fn = [&](void* p)
is a lambda, and cannot be reduced to a function pointer because it involves a capture.
void f(std::function<void(void*)> fn)
will work. http://ideone.com/E7vvyW
#include <functional>
struct A
{
A(int)
{}
};
void f(std::function<void(void*)> fn)
{
A a(0);
fn(&a);
}
int main()
{
int n = 0;
auto fn = [&](void* p)
{
//
// error C2664: 'void f(void (__cdecl *)(void *))' :
// cannot convert parameter 1 from
// 'main::<lambda_b20f735b061d78dbb0f2f653ecbb482f>'
// to 'void (__cdecl *)(void *)'
//
new (p) A(n);
};
f(fn);
}
I just have a very basic class that gives with functions that return the winning team of a match.
here's team.cpp
class teams
{
string teamName;
string teamName2;
int score;
int score2;
public:
teams ();
void set_team1();
void set_team2();
string get_score()
{
if (score > score2)
{
return teamName;
}
else
{
return teamName2;
}
}
private:
void teams::set_team1(string teamName, int score)
{
this->teamName=teamName;
this->score=score;
}
void teams::set_team2(string teamName2, int score2)
{
this->teamName2=teamName2;
this->score2=score2;
}
};
and here's is the line where i'm getting the error in the main method. I'm trying to create a teams object.
firstTeam.set_team1(teamName, score);
firstTeam.set_team2(teamName2, score2);
Visual studio comes up and says "error: no instance of overloaded function "team::set_team1" matches the argument list".
What am I missing?
This is the exact error I get:
1>c:\users\lab8.cpp(31): error C2664: 'void teams::set_team1(std::string,int)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::string'
1> with
1> [
1> _Ty=std::string
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\lab8.cpp(32): error C2664: 'void teams::set_team2(std::string,int)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::string'
1> with
1> [
1> _Ty=std::string
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> Generating Code...
1>
1>Build FAILED.
error C2664: 'void teams::set_team1(std::string,int)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::string'
From the error message, it is clear that first parameter isn't of type std::string. It is actually a std::vector. So,
firstTeam.set_team1(teamName, score); // Check what is the type of teamName
If you can see that teamName is actually a std::string, then check whether you are compiling the right file. Save the file and try again because the code you posted and the error message has no relation.
Compiler don't provide default constructor( constructor with no arguments ) in case your class overloads the constructor.
class teams
{
string teamName;
string teamName2;
int score;
int score2;
// ...
public:
teams( string t, int s ) : teamName(x), score(s)
// Initializer list
{}
};
But the I don't understand, why you have teamName2, score2 members as members of teams. What if there are 10 teams? Just have an instance for each team and compare them with other instances of teams.
You have declared the two methods without parameters. Convert:
void set_team1();
void set_team2();
into:
void set_team1(string, int);
void set_team2(string, int);