#include <iostream>
usingnamespace std;
class CNumbers {
protected:
int x, y;
public :
void Passer(int a, int b) {
x = a;
x = b; }
virtualint Result() = 0;
};
class CAddition: public CNumbers {
int Result() { return x+y;}
};
class CSubtraction: public CNumbers {
int Result() { return x-y;}
};
int main() {
CNumbers *pointer1, *pointer2;
int a, b;
cin >> a >> b;
Passer(a, b);
pointer1 = new CAddition;
pointer2 = new CSubtraction;
cout << pointer1->Result() << endl;
cout << pointer2->Result() << endl;
delete pointer1;
delete pointer2;
}
ERROR: error C3861: 'Passer': identifier not found.
I tried using the scope sign (::), but then it just genrated another error.
Help me please!
Thanks in advance
Passer is a member function just like Result. You have to call it the same way as you
call Result -- that is, with an instance.
But what you are trying to do is essentially write a useful constructor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class CNumbers {
public:
CNumbers( int a, int b ) : x( a ), y( b ) {}
};
class CAddition : public CNumbers {
public:
CAddition( int a , int b ) : CNumbers( a, b ) {}
};
int main() {
CAddition adder( 3, 4 );
std::cout << adder.Result() << std::endl;
}