정적 정수가 아닌 정수를 초기화하려고합니다. 그러나 그것은 개인적인 매개 변수를 필요로합니다. 이 정수형 인 경우는 클래스 본문에 배치하고 다른 즉,의 값을 하나 개의 변수를 수 있도록 허용 할 수 정적 멤버가 아닌 정수 멤버 인 클래스 멤버 초기화
static const int A=0;
static const int B=A;
하지만 비 필수로 클래스 본체의 외부 초기화해야
하지만, 회원들은 사적인 자리를 지키고 있기 때문에 클래스 본체 밖에서도 범위를 벗어납니다. 그들은 비공개 예//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);
이용시 : X의
는 이용시 : Y, 이용시 :: RAD, 이용시 :: COL이 범위를 벗어난다. 정적 const를 초기화 할 때마다 새 인스턴스가 만들어 질 때마다 호출되는 생성자에 넣지 않기를 바랄 것입니다. 예를
//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);
}
를 들어
는 위의 I 위의 이유로 사용하지 않는 원하는대로 작동하는 것 같다.
해결 방법이 있습니까? 회원들을 공개하지 않고.
감사