Ordering of class definitions

A

Anon Email

Hi People,

Quick question. Do class definitions for base classes (and for classes
of embedded objects) have to appear prior to their derived classes? I
would have thought that matters of ordering would not be so important.

Cheers,

Deets
 
R

Rolf Magnus

Anon said:
Hi People,

Quick question. Do class definitions for base classes (and for classes
of embedded objects) have to appear prior to their derived classes?

Yes. If those classes are not defined yet at this point, how would the
compiler know anything about them?
I would have thought that matters of ordering would not be so
important.

They are important.
 
K

Kevin Saff

Anon Email said:
Hi People,

Quick question. Do class definitions for base classes (and for classes
of embedded objects) have to appear prior to their derived classes? I
would have thought that matters of ordering would not be so important.

Cheers,

Deets

Quick answer. Yes.

Slightly longer answer. You might be able to alleviate the problem (for
contained members) by just declaring the classes and storing them in a smart
pointer, since Foo does not need to be defined for you to have a Foo&, a
Foo*, or a boost::scoped_ptr <Foo>.

HTH
 
M

Marko Becirevic

Quick question. Do class definitions for base classes (and for classes
of embedded objects) have to appear prior to their derived classes? I
would have thought that matters of ordering would not be so important.

Of course. How would othervise compiler know how to properly compile derived
class?

One solution is to write an interface in a separate file, and then just to
include that file in derived class file.
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top