Type keywords (class, enum, struct, union):
*class
*enum
class foo {
int x;
public:
int get_x();
void set_x(int new_x);
};
class foo; // elaborated type specifier -> forward declaration
class bar {
public:
bar(foo& f);
};
void baz();
class baz; // another elaborated type specifer; another forward declaration
// note: the class has the same name as the function void baz()
class foo {
bar b;
friend class baz; // elaborated type specifier refers to the class,
// not the function of the same name
public:
foo();
};
template <class T>
const T& min(const T& x, const T& y) {
return b < a ? b : a;
}
class precedes the name of the parameter. Since the argument for a template template parameter can only be a class template, the use of class here is redundant. However, the grammar of C++ requires it.
template <template <class T> class U>
// ^^^^^ "class" used in this sense here;
// U is a template template parameter
void f() {
U<int>::do_it();
U<double>::do_it();
}
template <class T>
class foo {
};
foo<class bar> x; // <- bar does not have to have previously appeared.
enum class Format {
TEXT,
PDF,
OTHER,
};
Format f = F::TEXT;