-
1
- #1
How do you declare a class variable without initiallising it?
I would like to be able to declare a variable of type AClass outside of any methods within my class, without initiallising the variable until the constructor is called (i.e. initiallise the variable within the constructor). This way, the variable would be accessible throughout the class.
For example, what I would like:
/***START CODE***/
class MyClass{
private:
//Like in Java- just declare, don't initiallise.
ANamespace::AClass AClassInstance;
public:
MyClass(){
// Initiallise here.
AClassInstance(new ClassBody());
}
}
/***END CODE***/
The above does not work, because it seems that you can't just declare an class variable in C++ without initiallising it. Or can you??
Is there a way to declare a class variable without instantiating it?
Any help would be greatly appreciated.
Thanks,
Brad.
I would like to be able to declare a variable of type AClass outside of any methods within my class, without initiallising the variable until the constructor is called (i.e. initiallise the variable within the constructor). This way, the variable would be accessible throughout the class.
For example, what I would like:
/***START CODE***/
class MyClass{
private:
//Like in Java- just declare, don't initiallise.
ANamespace::AClass AClassInstance;
public:
MyClass(){
// Initiallise here.
AClassInstance(new ClassBody());
}
}
/***END CODE***/
The above does not work, because it seems that you can't just declare an class variable in C++ without initiallising it. Or can you??
Is there a way to declare a class variable without instantiating it?
Any help would be greatly appreciated.
Thanks,
Brad.