Nested classes in VC++ 2005

G

gbook

I'm trying to nest classes and access the variables in each one from
the other. I mainly just want to access the outer class from the inner
class. Here is the code I have so far... It compiles, but I can't
declare an instance of the inner class inside the outer class.

class ImageData
{
.... ...
....
class LoadFile;
// LoadFile* loadFile; // doesn't compile this line!
friend class LoadFile;
};

/* class to load all different types of files */
class ImageData::LoadFile
{
friend class ImageData;
public:
LoadFile(ImageData *imgdata);
~LoadFile(void);

private:
ImageData *imgData;
};


How can I go about this? Is there something special about VC++2005?

-Greg
 
G

gbook

It turns out it works just fine. I had declared a function called
"LoadFile" in the outer class... which was preventing it from
compiling. VC++ error messages were not too helpful in that case. I
guess thats a benefit of reducing class size, its easier to navigate
and catch errors. Now that they're separated, I should be able to catch
more errors.
 
M

mlimber

gbook said:
I'm trying to nest classes and access the variables in each one from
the other. I mainly just want to access the outer class from the inner
class. Here is the code I have so far... It compiles, but I can't
declare an instance of the inner class inside the outer class.

class ImageData
{
... ...
...
class LoadFile;
// LoadFile* loadFile; // doesn't compile this line!
friend class LoadFile;
};

/* class to load all different types of files */
class ImageData::LoadFile
{
friend class ImageData;
public:
LoadFile(ImageData *imgdata);
~LoadFile(void);

private:
ImageData *imgData;
};


How can I go about this? Is there something special about VC++2005?

-Greg

Uncommenting that line, I get no compiler error on VC++2003 or 2005.
Please post a complete but minimal sample which demonstrates the
problem and which we can copy and paste into our editors and try to
compile with no modifications (e.g., get rid of the ... and uncomment
the problem line).

Cheers! --M
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top