Please help, I can’t figure out why my code isn’t working.
error: invalid use of incomplete type ‘class StatePair’
31 | StatePair<T1, T1>::StatePair(){
| ^
main.cpp:61:33: error: ‘endl’ was not declared in this scope
61 | cout << key << “: ” << value << endl;
| ^~~~
CODE:
#define STATEPAIR
using namespace std;
template<typename T1, typename T2>
class StatePair {
public:
StatePair();
StatePair(T1 userKey, T2 userValue);
void SetKey(T1 newkey);
void SetValue(T2 newVal);
T1 GetKey();
T2 GetValue();
void PrintInfo();
public:
T1 key;
T2 value;
};
template<typename T1, typename T2>
StatePair<T1, T1>::StatePair(){
}
template<typename T1, typename T2>
StatePair<T1, T2>::StatePair(T1 userKey, T2 userValue) {
key = userKey;
value = userValue;
}
template<typename T1, typename T2>
void StatePair<T1, T2>::SetKey(T1 newKey) {
key = newKey;
}
template<typename T1, typename T2>
void StatePair<T1, T2>::SetValue(T2 newVal){
value = newVal;
}
template<typename T1, typename T2>
T1 StatePair<T1, T2>::GetKey() {
return key;
}
template<typename T1, typename T2>
T2 StatePair<t1, T2>::GetValue() {
return value;
}
//TODO: Define PrintInfo() method
template<typename T1, typename T2>
void StatePair<T1, T2>::PrintInfo() {
cout << key << ": " << value << endl;
}
````#endif
I've added namespace std thinking that would solve my issues.
New contributor
Annalyn Cabuena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.