Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

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
 
Old December 16th, 2008, 06:52 AM
Authorized User
 
Join Date: Dec 2008
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default inheritance

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 .
 
Old December 16th, 2008, 06:01 PM
Authorized User
 
Join Date: Nov 2008
Posts: 15
Thanks: 1
Thanked 1 Time in 1 Post
Default

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..
 
Old December 16th, 2008, 08:14 PM
Authorized User
 
Join Date: Dec 2008
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanhks a lot , jabney. I understand .





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritance michaelcode ASP.NET 2.0 Basics 5 September 26th, 2006 01:40 PM
Inheritance abhi_bth ASP.NET 1.0 and 1.1 Basics 0 September 23rd, 2006 10:03 AM
Need help with inheritance filip BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 August 25th, 2006 09:38 PM
c# inheritance bhohman C# 2 March 26th, 2004 01:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.