Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i have a class within a class?

Status
Not open for further replies.

nbgoku

Programmer
May 25, 2004
108
US
ok can i have a class inside of another class?

1.h file

Code:
#pragma once

// CDRPDlg dialog
class CDRPDlg : public CDialog
{
     protected: //....
     public: 
              	class Filter
	        {
		     float *fil_data;
		     static float dc1d, dc2d;
		     int dim[2];
	           public:
		     Filter(int,float,int);
		     ~Filter();
	        };
     //....
};


also does the command extern work in Class's?
 
Yes, you may include class declarations into your classes. The only special effect is internal class names scope. Use
CDRPDlg::Filter outside outer class scope (i.e. member functions bodies).
 
sweet, it seems to partially work now :)

but when dealing with the code above, is there a way i can define a variable in CDRPDlg to also be available in Filter?


Code:
#pragma once

// CDRPDlg dialog
class CDRPDlg : public CDialog
{
     protected: //....
     public: 
            float t;
            //
            class Filter
            {
             float *fil_data;
             static float dc1d, dc2d;
             int dim[2];
               public:
             Filter(int,float,int);
             ~Filter();
            };
     //....
};

im trying to get float t to be available for both classes, so that both classes can change it around all they want
 
Var t available in all classes because of it's public. But it's common access rules: you must refer to it via its class object (or via pointer/reference to an object). This inner class is not a child of its outer class, you can't simply refer to t (w/o object) in Filter's member functions bodies.
Don't get confused with inner class declaration and class inheritance...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top