Container to pointers of inherited objects

A

axel22

Hello.
Please take a look at this piece of code:


class baseC {
//...
};

class derivedC : baseC {
//...
};


int main() {
baseC b1;
derivedC d1;
std::vector<baseC*> vex;

vex.push_back(&b1);
vex.push_back(&d1);


return 1;
}

Compiler returns an error on the second push_back - type cast:
conversion from 'derivedC * __w64' to 'baseC * const' exists, but is
inaccessible.
Can anyone tell me how to do this without the explicit cast, such as
(baseC *)(&d1);

thnx.
 
D

David Harmon

On 13 Aug 2006 12:41:34 -0700 in comp.lang.c++, (e-mail address removed)
wrote,
Compiler returns an error on the second push_back - type cast:
conversion from 'derivedC * __w64' to 'baseC * const' exists, but is
inaccessible.

class derivedC : public baseC {
 
A

axel22

David Harmon je napisao/la:
On 13 Aug 2006 12:41:34 -0700 in comp.lang.c++, (e-mail address removed)
wrote,

class derivedC : public baseC {

What do you know, it works. I thought public inheritance was the
default inheritance.

Thnx a lot!
 
C

Clark S. Cox III

David Harmon je napisao/la:

What do you know, it works. I thought public inheritance was the
default inheritance.

It is default for struct, but not for class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top