【发布时间】:2022-01-21 10:33:52
【问题描述】:
我希望看到有关 make_unique 等构造函数的智能感知。我查看了 make_unique 并尝试了以下操作(我可能是错的),但没有成功。
以下代码显示了我想要做什么,而不是问题。
#include <memory>
struct Struct
{
Struct(int a)
{
}
};
template <typename Type, typename... Args>
Type* make_struct(Args&&... args)
{
return new Type(std::forward<Type>(args)...);
}
int main()
{
// std::make_unique can see the constructor in intelliSense.
std::unique_ptr<Struct> a = std::make_unique<Struct>(3);
// make_struct can`t see the constructor in intelliSense.
std::unique_ptr<Struct> c(make_struct<Struct>(3));
}
【问题讨论】:
-
make_struct有什么问题?除了不使用转发引用是 -
您可能需要从一个更简单的练习开始。发生了几件事情,不清楚从哪里开始解释。
-
I want the variadic template to appear as constructor parameters你想写template<typename A, template <typename... Args> class B> Struct (B<A> arg);?这里B是一个可变参数模板,出现在Struct的构造函数中。你能解释一下你为什么要制作make_unique2,为什么它在std里面,和你的问题有什么关系? -
"//make_struct在intelliSense中看不到构造函数。"什么意思?此行之后的行编译得很好,并且在 VS 中没有显示任何问题。顺便说一句,您在谈论哪个构造函数?
std::unique_ptr<Struct>的自动补全中显示的构造函数 3/7 是std::unique_ptr<Struct>::unique_ptr(Struct*)。
标签: c++ visual-studio-2019 intellisense variadic-templates