Answer the question
In order to leave comments, you need to log in
Why write class in class object declaration?
Usually they don’t write like that, but I saw one code where it is almost everywhere.
For example:
class prettyClass
{
// just class
}
int main()
{
class prettyClass obj; // class?
std::cin.get();
return 0;
}
Answer the question
In order to leave comments, you need to log in
If a function or a variable exists in scope with the name identical to the name of a class type, class can be prepended to the name for disambiguation, resulting in an elaborated type specifier.
class Foo; // forward declaration of a class
class Bar { // definition of a class
public:
Bar(int i) : m_i(i) {}
private:
int m_i;
};
template <class T> // template argument
void qux() {
T t;
}
int main()
{
Bar Bar(1);
class Bar Bar2(2); // elaborated type
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question