Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Я в шоке... не компилится класс в 3 строки


Автор: suborg 12.5.2003, 17:50
class Command
{
public:
static const int ctType=5;
};

Что здесь не так?
Не компилится под Visual C 6.0
Под gnu вроде всё в порядке. Но почему под VC не идёт?!

Автор: man2002ua 12.5.2003, 18:08
Код
CAUSE
The compiler does not support in-place initialization of static const integral member data as specified in the C++ standard (section 9.2) quoted in the following:

4 - A member-declarator can contain a constant-initializer only if it declares a static member of integral or enumeration type.



RESOLUTION
Use one of the following Resolutions:

Use enum instead of static const int:

enum{x = 3};
Instantiate the member outside the class:

const int A::x=3;



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


Автор: DENNN 12.5.2003, 18:22
Потому что инициализация данных класса должна происходить в конструкторе.
А объявление вида int ctType()=0; означает чисто виртуальную функцию, имнно к такому виду и пытается привести твой код компилятор (и правильно делает).

Автор: Fantasist 13.5.2003, 16:03
В объявлении класса инициализация не допустима.
Нужно так:

Цитата
class Command
{
public:
static const int ctType;
};

static const int Command::ctType=5;


Автор: suborg 17.5.2003, 14:35
о... ништяк smile.gif
Спасибо!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)