oop errors and questions
Hi!
in my code i have a baseclass, lets cale it base, within which i have a pure virtual function like
virtual virtfunc() = 0;
my question now is: Does the function virtfunc() have to have the same type and number of arguments in the derived classes? The effect i want to achieve is that two different subclasses have this function but with different declarations...got it?
My secon question is: in my main function i have a pointer of type base but when i set it to point to one of the derived classes i get a compile time error wich says:
"members of baseclass not visible in derived class, due to private inheritance".....i find this strange since i have declared all nonpublic members as protected in baseclass....
any ideas?
--Spencer
--Spencer"All in accordance with the prophecy..."
Q1: Yes, they all have to have the same signature (as it''s called)--the type and parameters must be the same. If they are not, they are treated as two separate functions--this is called overloading a function.
If you want derived classes to have different arguments, it sounds like your is-a relationship between your derived and base class is not true. You may want to rework things, but we''ll need more info to give better suggestions.
Q2: Your compiler may generate the same error text for private & protected. They''re both hidden from non-member functions. Since main is not part of a class, it can only access the public data members of any class.
If you want derived classes to have different arguments, it sounds like your is-a relationship between your derived and base class is not true. You may want to rework things, but we''ll need more info to give better suggestions.
Q2: Your compiler may generate the same error text for private & protected. They''re both hidden from non-member functions. Since main is not part of a class, it can only access the public data members of any class.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement