Note that there are some explanatory texts on larger screens.

plurals
  1. POInitialise static const, non-integral, class member with a private member
    text
    copied!<p>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</p> <pre><code>static const int A=0; static const int B=A; </code></pre> <p>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.</p> <p>For example</p> <pre><code>//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); </code></pre> <p>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. </p> <p>For example</p> <pre><code>//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); } </code></pre> <p>The above seems to work however I wish not to use it for the above reason.</p> <p>Is there a work around. Without making the members public.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload