Hi, I am kind of newbie for C++. I actually come from JAVA world
The thing I am trying to do is to create some static and constant variables. However, I could not. Actually I succeeded when I create MIN_VOLUME variable only but it failed when I added more. Can someone lead me what the real problem is and how to succeed?
Header File:
class THECLOUD_API ACloud : public AActor
{
GENERATED_UCLASS_BODY()
static const float MIN_VOLUME;
static const float MAX_VOLUME;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects)
float chargeLevel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects)
float currentVolume;
};
CPP File:
#include "TheCloud.h"
#include "Cloud.h"
const float ACloud::MIN_VOLUME = 1.f;
const float ACloud::MAX_VOLUME = 10.f;
ACloud::ACloud(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
chargeLevel = 0.f;
currentVolume = MIN_VOLUME;
}
Error I get:
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
error C2589: 'constant' : illegal token on right side of '::'
error C4091: '' : ignored on left of 'const float' when no variable is declared
error C2143: syntax error : missing ';' before '::'
error C2059: syntax error : '::'
ADDITIONAL INFO
- A demonstration video is added : Video Link
-
Strange things happen. The code below compiles fine
Is this a compiler bug issue or what?UCLASS()
class ACloud : public AActor
{
GENERATED_UCLASS_BODY()const float VOLUME_MIN = 1.0f; const float VOLUME_MAX = 10.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects) float chargeLevel; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FlyingObjects) float currentVolume;};