"class classUnderTest##name##Test : public Test, name##Setup" , where name##Setup has not been define yet, how can it be used. Please give some clarification regarding this kind of syntax. I would like to run and compile some of this kind of code in visual studio 2010. It would be good, if I am referred to some tutorial website.
Re: I need some explanation about the following piece of code
Originally Posted by jenny_wui
Thanks for the reply.But the following piece of code when I tried to paste in visual studio 2010, it showed error.
That is not a full program. You don't even show usage of the macro.
Please give some clarification regarding this kind of syntax.
Do you understand what "token pasting" is and what the C++ preprocessor handles token pasting? That is all the information you need to look up to figure out what ## is supposed to do.
Re: I need some explanation about the following piece of code
Hi, I am familiar with C++, I went through the preprocessor and token pasting, I have a few questions in the light of the picture attached, it would cbe a great help in order to clarify my conception:
1. “name##Setup” class has not yet been defined. How that class can be inherited by “class classUnderTest##name##Test”? Please give some clarification.
2. What does the encircled line 2 (i.e. #name “Test”) mean?
3. What does the encircled line 3 imply? (name##Setup::setup()) as name##Setup class has notyet been defined?
4. At marking 4, “classUnderTest##name##Instance”, is it an instance of “classclassUnderTest##name##Test”, usually this kind of definition is used while writing stuct.
5. In 5, the function “runTest” has again been defined, why?
Re: I need some explanation about the following piece of code
Originally Posted by jenny_wui
Hi, I am familiar with C++, I went through the preprocessor and token pasting, I have a few questions in the light of the picture attached, it would cbe a great help in order to clarify my conception:
You didn't circle the most important part of the whole thing, and that is the first line.
Do you know what that #define does? What those parameters are? If you do, then all you need to do is see what happens if you invoked the macro with a sample line:
Code:
TESTWITHSETUP(name1, name2)
Take that line, apply what you learned about token pasting, and expand that macro with those parameters. What do you ultimately end up with once the macro is expanded?
Re: I need some explanation about the following piece of code
Originally Posted by jenny_wui
1. “name##Setup” class has not yet been defined. How that class can be inherited by “class classUnderTest##name##Test”? Please give some clarification.
A macro need not have the class predefined. When the macro is expanded (something I asked you to do in the previous post, so that you see what it does), then the compiler will expect that the class is already defined, but not before. That macro is perfectly valid.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.