G
Guenther Sohler
This is probably very easy to answer but for me its new.
Yesterday I realized the need to be able to define a class within another
one. So I have written some test code and its almost syntax error free.
My first goal is to count the Outer classes with a global variable, which
works fine
But then I want to count the Inner classes within the Outer class.
The Varibale innernum is global in repsect to the Class Inner, but
I dont know how to access it.
The error I am getting is
class.cpp: In constructor `Outer::Inner::Inner()':
class.cpp:48: error: type `Outer' is not a base type for type `Outer::Inner'
Its commented in the testcode below. If somebode could show me the right
syntax, I would be happy.
rds
#include <stdio.h>
int outernum=0;
class Outer
{
public:
Outer(void);
~Outer();
void test(void);
int innernum;
class Inner
{
public:
Inner(void);
~Inner();
};
};
Outer::Outer(void)
{
printf("Outer::Outer\n");
innernum=0;
outernum++;
printf("outernum=%d\n",outernum);
}
Outer::~Outer()
{
printf("Outer::~Outer\n");
outernum--;
printf("outernum=%d\n",outernum);
}
void Outer::test(void)
{
printf("Outer::test\n");
Inner a;
Inner b;
}
Outer::Inner::Inner(void)
{
printf("Outer::Inner::Inner\n");
// Outer::innernum++;
// printf("innernum=%d\n",Outer::innernum);
}
Outer::Inner::~Inner()
{
printf("Outer::Inner::~Inner\n");
// Outer::innernum--;
// printf("innernum=%d\n",Outer::innernum);
}
int main(void)
{
Outer a;
Outer b;
a.test();
return 0;
}
Yesterday I realized the need to be able to define a class within another
one. So I have written some test code and its almost syntax error free.
My first goal is to count the Outer classes with a global variable, which
works fine
But then I want to count the Inner classes within the Outer class.
The Varibale innernum is global in repsect to the Class Inner, but
I dont know how to access it.
The error I am getting is
class.cpp: In constructor `Outer::Inner::Inner()':
class.cpp:48: error: type `Outer' is not a base type for type `Outer::Inner'
Its commented in the testcode below. If somebode could show me the right
syntax, I would be happy.
rds
#include <stdio.h>
int outernum=0;
class Outer
{
public:
Outer(void);
~Outer();
void test(void);
int innernum;
class Inner
{
public:
Inner(void);
~Inner();
};
};
Outer::Outer(void)
{
printf("Outer::Outer\n");
innernum=0;
outernum++;
printf("outernum=%d\n",outernum);
}
Outer::~Outer()
{
printf("Outer::~Outer\n");
outernum--;
printf("outernum=%d\n",outernum);
}
void Outer::test(void)
{
printf("Outer::test\n");
Inner a;
Inner b;
}
Outer::Inner::Inner(void)
{
printf("Outer::Inner::Inner\n");
// Outer::innernum++;
// printf("innernum=%d\n",Outer::innernum);
}
Outer::Inner::~Inner()
{
printf("Outer::Inner::~Inner\n");
// Outer::innernum--;
// printf("innernum=%d\n",Outer::innernum);
}
int main(void)
{
Outer a;
Outer b;
a.test();
return 0;
}