Why wont this work???
What am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
using namespace std;
template <class T>
class Math{
public:
T add(T *x, T *y);
T GetInfo();
protected:
T* number1 = new T;
T* number2 = new T;
private:
};
template <class T>
T Math<T>::add(T *x, T *y)
{
return(*x + *y);
}
template <class T>
T Math<T>::GetInfo()
{
cout << "enter number: ";
cin >> *number1;
cout << "enter number: ";
cin >> *number2;
}
int main()
{
Math<double> MathObject;
MathObject.GetInfo();
cout << MathObject.add(*number1, *number2) <<endl;
//I also tried MathObject->add(*number1, number2);
delete *number1, *number2;
}
|
What are you doing wrong?
1 2
|
cout << MathObject.add(*number1, *number2) <<endl;
delete *number1, *number2;
|
Where is *number1 and *number2 in the main scope?
EDIT:
Don't bother with templates until you actually understand C++.
Last edited on
Topic archived. No new replies allowed.