リファクタリングを見つけて置き換えた後、私はこの宝石に行き着きました:
const class A
{
};
「constclass」とはどういう意味ですか?コンパイルは問題ないようです。
そのconst
例ではこれは無意味であり、コンパイラはエラーを返すはずですが、これを使用してクロージング}
との間にそのクラスの変数を宣言すると、;
それらのインスタンスは次のように定義されますconst
。
const class A
{
public:
int x, y;
} anInstance = {3, 4};
// The above is equivalent to:
const A anInstance = {3, 4};
「constclass」とはどういう意味ですか?コンパイルは問題ないようです。
私にとってはそうではありません。あなたのコンパイラは丁寧でそれを無視しているだけだと思います。
編集:うん、VC ++は黙ってconstを無視し、GCCは文句を言う。
あなたがこれを持っていた場合:
const class A
{
} a;
その場合、それは明らかに「a」が定数であることを意味します。そうでなければ、それはおそらく無効なc++だと思います。
次の例のように、後でクラスのインスタンスを宣言しない限り、意味がありません。
const // It is a const object...
class nullptr_t
{
public:
template<class T>
operator T*() const // convertible to any type of null non-member pointer...
{ return 0; }
template<class C, class T>
operator T C::*() const // or any type of null member pointer...
{ return 0; }
private:
void operator&() const; // Can't take address of nullptr
} nullptr = {};
nullptr
C++0xを待っている場合の暫定的な実装。