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
115 views
in Technique[技术] by (71.8m points)

'class' keyword in variable definition in C++

Before anyone asks, yes, this is part of a homework, and yes, I did a lot of Googling before asking. I spent the last hour searching intensively on Google with many, many different keywords, but just could not find anything.

So here goes the question :

What does the following variable definition mean: class MyClass* myClass;?

I tried that code with something like class MyClass* myClass = new MyClass(); and found that it simply creates a pointer to a new instance of MyClass.

So, what's the advantage of using the class prefix? Does it make any difference?

Does someone have a link to some resources about it? I simply could not find anything (it's really, really hard to find things other than "class definition"!).

Thanks a lot!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

An elaborated type specifier is a type name preceded by either the class, struct, enum, or union keyword.

class identifier 
struct identifier 
enum identifier 
union identifier

An elaborated type specifier is used either for emphasis, or to reveal a type name that is hidden by the declaration of a variable with the same name in the same scope.

source


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

2.1m questions

2.1m answers

60 comments

57.0k users

...