Home > Back-end >  C macro multiple function call//how to return a pointer type?
C macro multiple function call//how to return a pointer type?

Time:10-27

 
The class test {public: void fun () {}}

The class layerManager
{
Public:
The static layerManager * getlayerManagerHandler ()
{
The static layerManager& Rh=null;
if(! Rh)
{
Rh=new layerManager;
}
Return rh;
}
Template
T * getLayer (const STD: : string layername)
{
The test * p=new test;
Return dynamic_cast & lt; T> (p);
}
Void fun () {}
Private:
LayerManager () {}
~ layerManager () {}
};

# define RES (name type)
LayerManager: : getlayerManagerHandler () - & gt; Fun (); \
LayerManager: : getlayerManagerHandler () - & gt; GetLayer (name);

Int main ()
{
STD: : string ss="a";
The test * p=RES (ss, test)
p-> Fun ();
Retrun 0;
}

CodePudding user response:

Comma expression, comma expression of value is the statement on the right, so you can like this:
 # define RES (name, type) \ 
(\
LayerManager: : getlayerManagerHandler () - & gt; Fun (),,
LayerManager: : getlayerManagerHandler () - & gt; GetLayer (name) \
)

CodePudding user response:

More conventional practice is layered and function, as follows:
 template 
T * fun_ (const STD: : string & amp; SLayerName)
{
LayerManager: : getlayerManagerHandler () - & gt; Fun ();
Return layerManager: : getlayerManagerHandler () - & gt; GetLayer (sLayerName);
}

# define RES (name, type) fun_ & lt; Type> (name)
  • Related