Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

c++ - What does "const class" mean?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...