What does “const class” mean?

前端 未结 5 1878
不思量自难忘°
不思量自难忘° 2020-12-14 14:34

After some find and replace refactoring I ended up with this gem:

const class A
{
};

What does \"const class\" mean? It seems to compile ok

5条回答
  •  不知归路
    2020-12-14 15:24

    The const is meaningless in that example, and your compiler should give you an error, but if you use it to declare variables of that class between the closing } and the ;, then that defines those instances as const, e.g.:

    
    const class A
    {
    public:
        int x, y;
    }  anInstance = {3, 4};
    
    // The above is equivalent to:
    const A anInstance = {3, 4};
    

提交回复
热议问题