You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
I'm a newcomer to programming , help me !!!
If I declare :
class B : class A
{
.............
};
What kind of inheritance of B from A ? public , protected , private .
I just guess that's private ??? Help me!!! Thanks a lot .
I just tried some tests and the default class inheritance is private. Here's the compiler message:
1>c:\users\james\documents\visual studio 2008\projects\beginning visual c++ 2008\inh_test\inh_test\inh.cpp(24) : error C2247: 'A::i' not accessible because 'B' uses 'private' to inherit from 'A'
This was using the following class declarations:
Code:
class A
{
public:
A():i(10){}
int i;
};
class B : A
{
public:
B():j(i){}
int j;
};
The compiler error doesn't occur until the program tries to access class A's variable i.
Code:
B b;
b.i = 5;
Last edited by jabney; December 16th, 2008 at 06:04 PM..