473,474 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is this construction validate in C++?

class A
{
public:
...
protected:
...
private:
class B : public A { ... };
};

Because compiler gives me errors like:
- invalid use of undefined type `class A'
- forward declaration of `class A'

Thanks for replies

Dec 7 '06 #1
4 1017
ms****@gmail.com wrote:
class A
{
public:
...
protected:
...
private:
class B : public A { ... };
};

Because compiler gives me errors like:
- invalid use of undefined type `class A'
- forward declaration of `class A'

Thanks for replies
To inherit, you must have a complete type. A is not complete until the
end of its declaration block. A forward declaration should work:

class A {
.....
class B;
};

class A::B : public A {};
Dec 7 '06 #2
ms****@gmail.com wrote:
class A
{
public:
...
protected:
...
private:
class B : public A { ... };
};

Because compiler gives me errors like:
- invalid use of undefined type `class A'
- forward declaration of `class A'

Thanks for replies
No, you can only derive from a complete type. At the point
where you define 'B', 'A' has not been completely defined
yet.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 7 '06 #3
Thank you very much Matt...

Dec 7 '06 #4

ms****@gmail.com wrote:
class A
{
public:
...
protected:
...
private:
class B : public A { ... };
};
OTOH you can do:

template <typename T = void>
class A
{
public:
int value;
class B : public A<B{ public: int other_value;};
};
int main()
{
A<x;
x.value = 1;
A<>::B y;
y.value = 2;
y.other_value = 3;
}

HTH

regards
Andy Little

Dec 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
1
by: Anthony | last post by:
Hi, Can anyone help me out here, I'm looking for a design (pattern?) for a-synchronic construction of a class. I need this design in a framework which will run in a multithreaded system. I...
2
by: Steve | last post by:
Hi Folks, Sorry for this stupid question, but how do you handle errors during class construction. In other words, if I have a class that loads a file, and during loading, an error occurs, how do...
14
by: trying_to_learn | last post by:
i am on the chapter on copy construction in C++ in the code (see below), the author says if u pass the object by value as in HowMany h2 = f(h); ....then a bitwise object is created w/o calling...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
19
by: Bill Cohagan | last post by:
I'm constructing an ASP page that I'd like to test by writing a program that simulates "many" users hitting the submit button on a form. I assume it's possible to manually construct an httprequest...
7
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case...
15
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
1
by: pete m | last post by:
I would like to support stdio functions for an extremely primitive type system, as shown in the attached sample program, using dynamic creation of a va_list. I've tested it on successfully a...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.