Re: константа в классе
От: gear nuke  
Дата: 13.09.05 01:05
Оценка:
Здравствуйте, <Аноним>, Вы писали:

А>как объявить константу в классе?

А>мне нужно вот в таком вот виде:

А>
А>class A {
А>    const int F = 123;
А>};

class A {
    static const int F = 123;
};

А если компилятор такое не компилирует — выкиньте его и возмите нормальный .
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird (c) D.Knuth
Re[3]: константа в классе
От: gear nuke  
Дата: 13.09.05 01:23
Оценка:
Здравствуйте, <Аноним>, Вы писали:

А>>>
А>>>class A {
А>>>    static const int F = 123;
А>>>};
А>>>


А> : error C2258: illegal pure syntax, must be '= 0'

А> : error C2252: 'F' : pure specifier can only be specified for functions

MSVC 6.0 ф топку
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird (c) D.Knuth
Re[5]: константа в классе
От: gear nuke  
Дата: 13.09.05 01:23
Оценка:
Здравствуйте, _DAle_, Вы писали:

_DA>Константные члены могут быть проинициализированы значениями, известными только в рантайме.


Happily, you don't have to care about any of this anymore. Fairly late in the standardization game, the C++ standards committee patched the C++ standard to let static integer constants be initialized in their declarations:

class X
    {
public:
    static int const n = 10; // initialization OK
    void f2()
        {
        int a[X::n]; // OK
        }
    };

int const X::n = 10; // now an error -- multiple initialization
int const X::n; // definition OK, but might not be required
Visual C++ .NET compiles this properly. Visual C++ 6.0 interprets the initialization of X::n as an illegal pure virtual function declaration


cl.exe Episode XIII: Attack of the Standards &mdash; Bobby Schmidt. Microsoft Corporation
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird (c) D.Knuth
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.