Hi,
Im fairly new to C++ and have some problems to define a subobject in a class.
Lets say I have simple class that looks like this:
.h
#pragma once
#include "USimpleClass.generated.h"
UCLASS()
class XOF_API USimpleClass : public UObject
{
GENERATED_BODY()
private:
int Value;
int GetValue();
void SetValue(int AValue);
public:
// Default constructor. No parameters expected.
USimpleClass();
//Extended constructor. Integer parameter expected.
USimpleClass(int);
// Default destructor. No parameters expected.
~USimpleClass();
// Value property
__declspec (property (put = SetValue, get = GetValue)) int ValueProp;
};
.cpp
#include "XOF.h"
#include "USimpleClass.h"
USimpleClass::USimpleClass()
{
ValueProp = 42;
}
USimpleClass::USimpleClass(int InitialValue)
{
ValueProp = InitialValue;
}
USimpleClass::~USimpleClass()
{
}
int USimpleClass::GetValue()
{
return Value;
}
void USimpleClass::SetValue(int AValue)
{
if (AValue < 0)
{
Value = 0;
}
else
{
Value = AValue;
}
return;
}
So the class has two constructors. The default one (which initializes the value to 42); and anotherone that takes a parameter that is used to initialize the Value field (which is accesses via a property).
That all compiles lovely, but now I want to make this class (or better: an instance of it) a subobject of another, more complex, class.
That other class looks like this:
.h
#pragma once
#include "USimpleClass.h"
#include "UComplexClass.generated.h"
UCLASS()
class XOF_API UComplexClass : public UObject
{
GENERATED_BODY()
private :
int Foo;
USimpleClass HelperObj(69); // compiler error C2059 here
bool Bar;
public:
UComplexClass();
~UComplexClass();
};
.cpp
#include "XOF.h"
#include "UComplexClass.h"
UComplexClass::UComplexClass()
{
}
UComplexClass::~UComplexClass()
{
}
What am I doing wrong ?
Any help is appreciated
Cheers,
Klaus