预处理器宏中的typedef

时间:2016-04-21 11:33:44

标签: c++

我有一个像这样的宏定义,可以轻松地为类创建一个shared_ptr:

#define create_ptr(__TYPE__) typedef std::shared_ptr<__TYPE__>

我现在想要的是追加&#34; Ptr&#34;到类名,这样

create_ptr(MyClass)

会导致typedef名为MyClassPtr std::shared_ptr<MyClass> 我该如何做到这一点?

2 个答案:

答案 0 :(得分:4)

您需要令牌连接<p>Click the button to replace "blue" with "red" in the paragraph below:</p> <p id="demo"><a href = 'link1' > TAG1 </a> , <a href = 'link2' > TAG2 </a> , <a href = 'link3' > TAG3 </a></p> <p id="result"></p> <button onclick="myFunction()">Try it</button>

##

有关详细说明,请查看https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

答案 1 :(得分:4)

替代路线是使用声明:

template <typename T>
using sp = std::shared_ptr<T>;

sp<int> my_shared_int_pointer ....