Im am attempting to initialise a static const non-integral. However it requires parameters which are private. If it was of integral type you could place it in the class body and allow allow one variable to take the value of another ie
static const int A=0;
static const int B=A;
But as its non-integral it must be initialised outside of the class body, but as the members are private they are out of scope, outside the class body.
For example
//HEADER
class Person
{
static const float x;
static const float y;
static const int rad;
static const sf::Color col;
static const sf::Shape shape;
};
//CPP
const float Person::x=0;
const float Person::y=0;
const int Person::rad=16;
const sf::Color Person::col(255,0,0,255);
const sf::Shape shape=sf::Shape::Circle(Person::x,Person::y,Person::rad,Person::col);
Person::x,Person::y,Person::rad,Person::col is out of scope as they are private. As I am initialising a static const I would wish not to put it in the constructor which would be called everytime a new instance is created.
For example
//HEADER
class Person
{
static const float x;
static const float y;
static const int rad;
static const sf::Color col;
static const sf::Shape shape;
Person();
};
//CPP
const float Person::x=0;
const float Person::y=0;
const int Person::rad=16;
const sf::Color Person::col(255,0,0,255);
Person::Person()
{
const sf::Shape shape=sf::Shape::Circle(x,y,rad,col);
}
The above seems to work however I wish not to use it for the above reason.
Is there a work around. Without making the members public.
Thanks