Nested classes in VC++ 2005



 DEVELOP > c-Plus-Plus > Nested classes in VC++ 2005

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "gbook"
Date: 05 May 2006 01:29:53 PM
Object: Nested classes in VC++ 2005
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
.

User: "gbook"

Title: Re: Nested classes in VC++ 2005 05 May 2006 02:00:38 PM
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.
.

User: "mlimber"

Title: Re: Nested classes in VC++ 2005 05 May 2006 02:02:05 PM
gbook wrote:

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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER