In c++ I have an Abstract class A:
class A
{
public:
A(){}
virtual ~A(){}
virtual void out(std::ofstream& outFile) = 0;
virtual void in(std::ifstream& inFile) = 0;
};
And B class in which I want to use virtual methods:
class B : public A
{
public:
B();
double angle;
int index;
virtual void out(std::ofstream& outFile);
virtual void in(std::ifstream& inFile);
};
Now here is a question: I want to use B class variable like (int index) in virtual methods:
virtual void out(std::ofstrea& outFile)
{
outFile<< index << angle;
}
Here I get compiler error that angle and index are not declared in this scope. It is somewhat logical because this variables are not declared in class A.
Now how can I get access to variable angle and index in virtual methods?
Thanks for your help.
If you’re implementing the method outside the class, you don’t mark it as
virtualand you qualify its name: