Did you try to compile this? Simple question like this could just be tested. Learn to be more independent.
There is no harm in asking the question. Just because something can be compiled and appear to work doesn't mean it is correct.
Did you try to compile this? Simple question like this could just be tested. Learn to be more independent.
[quote name='D.Chhetri' timestamp='1351395282' post='4994627']
Did you try to compile this? Simple question like this could just be tested. Learn to be more independent.
template <int level>
struct Menu
{
Menu<level + 1> subMenu;
...
};
template<>
struct Menu<3> // hierarchy ends here
{
...
};
static void foo()
{
Menu<0> menu;
menu.subMenu.subMenu.subMenu; // ok
menu.subMenu.subMenu.subMenu.subMenu; // error, no such member
}
class Profiler {
public:
Profiler();
~Profiler() { }
// This gives us a global version without limiting us to only 1. We can make other Profiler
// objects if we want.
static Profiler &GetGlobalInstance() {
static Profiler prof;
return prof;
}
[...] stuff
};