I get an error:
request for member `setPairX' in `anotherPoint', which is of non-class type `Pair<float, int> ()()'
which I really do not understand... I only suspect there is something wrong with the default constructor, but I have no clue what.
I have my template in .h file (all declarations and definitions). The part I'm concerned is as follows:
Code:
template< class T1, class T2 >
class Pair {
public:
Pair();
Pair(const T1 &x, const T2 &y) : first(x), second(y) {}
// ~Pair();
void setPairX(const T1 &x);
void setPairY(const T2 &y);
T1 getPairX() const { return first; } //inline def
T2 getPairY() const { return second; } // inline def
// void swapPair();
private:
T1 first;
T2 second;
};
//definitions for the template
template< class T1, class T2 >
Pair< T1, T2 >::Pair()
{
first = 0;
second = 0;
}
template< class T1, class T2 >
void Pair< T1, T2 >::setPairX(const T1 &x)
{
first = x;
}
template< class T1, class T2 >
void Pair< T1, T2 >::setPairY(const T2 &y)
{
second = y;
}
If I call parametrized constructor, everything works fine. But when I call the default one, I get the compiler error I quoted.
That's how I call the default constructor in main:
Code:
Pair <float, int> anotherPoint();
anotherPoint.setPairX(1.05);
cout << anotherPoint.getPairX() << " is first in anotherPoint." << endl;
anotherPoint.setPairY(4);
cout << anotherPoint.getPairY() << " is second in anotherPoint." << endl;
Can you tell me what I'm doing wrong?
Also: maybe a stupid question. Do I need to define the destructor? If yes, how?