#include %26lt;cstdlib%26gt;
#include %26lt;iostream%26gt;
using namespace std;
int main(int argc, char *argv[])
{
class Printer {
protected:
int level;
public:
int getlevel();
};
int Printer::getlevel() {
return level;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Why doesn't that work?
Can someone help me with this C++ Inheritance problem?
You can't put member function definitions from nested classes outside the class declaration, at least not with Dev-C++. I'm not sure if any compiler would support that. If you defined the getlevel function right after the declaration it would work:
class Printer {
...
int getlevel() { return level; }
...
};
...
Reply:You should use that protected varible within class and subclass of that class. then only it works.
public: within that class and outside of the class
protected:within that class and subclasses of that class
private:within that class only and cannot be accessed anywhere except within the class.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment