I am developing a BlackBerry 10 apps with Cascades in C++.
I'm just a beginner, and this problem really confused me.
I have a class Parser
and a derived class LicenseParser
.
Class Parser {
// implementation
}
and
Class LicenseParser : public Parser {
// ...
public:
void Parse();
}
In another file:
Parser* p= new LicenseParser();
p->Parse();
But I got an error:
class Parser' has no member named 'parse'
The method Parse
is declared in the derived class so I know it can be used without declaring it in the Parser
class!
How should I correct this?
The error occurs because p
is a pointer to a Parser
, not a pointer to a LicenseParser
.
Despite the fact the you know the p
actually points to a LicenseParser
, your assignment to a base class pointer means that you choose to not let the compiler know anything about it.
You should either have a virtual Parse
member function in the base class, or have the variable p
be a LicenseParser*
instead.