c++ - variable + value macro expansion -
I tried my code without any consequences:
#include "Stdafx.h" #include & lt; Iostream & gt; #define R () (rand ()) #define H (a, b) (a ##b) #define S (a) (#a) #define CAT () H (S (distinct_name_), R ()) Int main (int argc, _TCHAR * argv []) {std :: cout & lt; & Lt; Cat () & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; Cat () & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; Cat () & lt; & Lt; Std :: endl; Return 0; }
I would like to get a result like this:
distinct_name_12233 distinct_name_147 distinct_name_435 different-code> Getting: The word 1 does not evaluate the function while taking arguments. Is it worth achieving ??
EDIT: In the end, I succeeded after a few hours, the pre-programmer still does weird things which I can not fully understand. Here goes:
#include "stdafx.h" #include & lt; Iostream & gt; Class Profiler {Public: Zero Show () {std :: cout & lt; & Lt; "Specific_station" & lt; & Lt; Std :: endl; }}; #define XX __LINE__ #define H (a, b) (a ## b) #define CAT (r) H (distinct_name_, r) #define GET_DISTINCT () CAT (XX) #define PROFILE () \ profiler GET_DISTINCT (); \ GET_DISTINCT () Show (); \ Int main (int argc, _TCHAR * argv []) {PROFILE () PROFILE () 0; }
And the output is:
distinct_instance distinct_instance
thanks __ line __
hint}
I think many people have already answered the question correctly But, as an alternative suggestion, if your preprocessor's __ time___
or __ line __
is applicable, you can get a line number instead of a result number or Can get a result over time.
Comments
Post a Comment