I have following macro for measuring time in header file:
#define TIMER_START(x) double ___timer__##x = (double) getTickCount();
#define TIMER_END(x) ___timer__##x = (getTickCount() - ___timer__##x) *1000 / getTickFrequency(); cout << "t" << ##x << ": " << ___timer__##x << endl;
The problem is, when I use this header file, the cout is not defined. Is there any option to use it this way? I have tried specifiing namespace but with no luck. Either ostream:: and std:: doesn’t contain definition for cout.
PS: I’m working in MSVS2010.
The name
couthas to be visible at the point where you invoke the macro. Writingis just like writing
and the same visibility rules apply.
I suspect that changing
couttostd::coutwill fix the problem. Of course you’ll need to include the appropriate header in any source file that invokes the macro.Some other issues:
Identifiers starting with underscores are reserved to the implementation. I believe C++ also reserves identifiers with embedded double underscores. You’re trying to avoid colliding with user-defined identifiers, but you risk colliding with compiler-defined or library-defined identifiers. It’s probably not going to cause any visible problems, but you should use some other unique prefix.
The trailing semicolons in your macro definitions are redundant; you’ll provide those when you invoke them: