Click here to Skip to main content
15,915,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Create a Service Pin
l a u r e n18-Dec-02 11:11
l a u r e n18-Dec-02 11:11 
GeneralRe: Create a Service Pin
Member 13661818-Dec-02 11:14
Member 13661818-Dec-02 11:14 
GeneralRe: Create a Service Pin
Nish Nishant18-Dec-02 11:14
sitebuilderNish Nishant18-Dec-02 11:14 
GeneralRe: Create a Service Pin
Anonymous18-Dec-02 17:15
Anonymous18-Dec-02 17:15 
GeneralRe: Create a Service Pin
Member 13661819-Dec-02 4:48
Member 13661819-Dec-02 4:48 
Generalself-upgrading program Pin
thisisnotfake18-Dec-02 10:53
thisisnotfake18-Dec-02 10:53 
GeneralTransparent the staticbox ?! Pin
Hadi Rezaee18-Dec-02 10:34
Hadi Rezaee18-Dec-02 10:34 
GeneralInheritance. Pin
WREY18-Dec-02 10:16
WREY18-Dec-02 10:16 
I am ALWAYS exploring and uncovering things in C++, and if by chance I believe I may have discovered something unusual, I revert to the various C++ textbooks for clarification and/or correction.

Here's an example of what I'm talking about: A publicly derived class ought to be able to access "protected" members of its base class. Well this sample exercise I did, doesn't seem to follow that rule.

This is what the compiler said, "error C2248: 'storename' : cannot access protected member declared in class 'Store'."

==============================================

class Store
{
etc.

protected:
string storename; // I should be able to access this member !!!!!!!
int storenum;
};


class Food : public Store
{
public:
Food(string na, int num, string foodItem, float retprice, int invAmt)
: Store(na, num)
{ etc. }

void Msg(string msg)
{
reinterpret_cast<<store*>>(this)->Msg("HQtrs"); // dbl angle brackets needed for msg
cout << '\n' << ((Store*)this)->storename << endl; // error here !!!!!!!

etc.
}
etc.
};

==============================

The reason I'm casting the 'this' pointer to Store is to qualify the data member to which I am referring.

But why is the compiler telling me that this publicly derived class cannot access the protected member of its base class?

Thanks for any help. I appreciate it.

Cool | :cool:

William
GeneralRe: Inheritance. Pin
Ravi Bhavnani18-Dec-02 10:23
professionalRavi Bhavnani18-Dec-02 10:23 
GeneralRe: Inheritance. Pin
WREY18-Dec-02 11:03
WREY18-Dec-02 11:03 
GeneralRe: Inheritance. Pin
Ravi Bhavnani18-Dec-02 11:23
professionalRavi Bhavnani18-Dec-02 11:23 
GeneralRe: Inheritance. Pin
WREY19-Dec-02 6:34
WREY19-Dec-02 6:34 
GeneralRe: Inheritance. Pin
Alvaro Mendez18-Dec-02 10:33
Alvaro Mendez18-Dec-02 10:33 
GeneralRe: Inheritance. Pin
WREY18-Dec-02 10:56
WREY18-Dec-02 10:56 
GeneralRe: Inheritance. Pin
Alvaro Mendez18-Dec-02 12:41
Alvaro Mendez18-Dec-02 12:41 
GeneralRe: Inheritance. Pin
WREY19-Dec-02 7:18
WREY19-Dec-02 7:18 
GeneralRe: Inheritance. Pin
Alvaro Mendez20-Dec-02 6:05
Alvaro Mendez20-Dec-02 6:05 
GeneralRe: Inheritance. Pin
WREY20-Dec-02 7:18
WREY20-Dec-02 7:18 
GeneralRe: Inheritance. Pin
Chris Richardson19-Dec-02 18:59
Chris Richardson19-Dec-02 18:59 
GeneralRe: Inheritance. Pin
WREY19-Dec-02 21:49
WREY19-Dec-02 21:49 
GeneralRe: Inheritance. Pin
Chris Richardson20-Dec-02 7:03
Chris Richardson20-Dec-02 7:03 
GeneralRe: Inheritance. Pin
WREY20-Dec-02 7:24
WREY20-Dec-02 7:24 
QuestionHow to delete an HBITMAP? Pin
Joan M18-Dec-02 9:37
professionalJoan M18-Dec-02 9:37 
AnswerRe: How to delete an HBITMAP? Pin
Christian Graus18-Dec-02 9:49
protectorChristian Graus18-Dec-02 9:49 
GeneralRe: How to delete an HBITMAP? Pin
Joan M18-Dec-02 9:59
professionalJoan M18-Dec-02 9:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.