【发布时间】:2020-02-16 18:18:57
【问题描述】:
在尝试通过 const 引用传递向量时,我收到以下智能感知错误(项目构建成功):
no instance of constructor "ObjOne::ObjOne" matches the argument list
argument types are: (std::vector<int, std::allocator<int>>)
我已在以下发生错误的最小可重现示例中进行了评论。在 Visual Studio 2017 中是否有解决此类问题的已知方法?
#include <vector>
#include <string>
#include <optional>
class ObjOne
{
public:
ObjOne(const std::vector<int>& p1) {}
};
class ObjTwo
{
private:
std::vector<int> testVec = { 1,2,3,4,5 };
std::optional<ObjOne> optObjOne;
public:
ObjTwo() {}
void makeObjOne()
{
this->optObjOne = ObjOne(this->testVec); // Issue arises here
}
};
int main()
{
auto myObjTwo = ObjTwo();
myObjTwo.makeObjOne();
return 0;
}
【问题讨论】:
-
请将您的问题简化为minimal reproducible example。我自己无法测试您现在显示的内容,因为代码不完整并且我没有看到任何明显的问题(或者我忽略了它),可能是因为不相关的代码太多。
-
vertex.h或texture.h标头可能存在问题,因此应将它们添加到问题中。还要检查并确保在不同的目录中没有这些标题的多个副本。 -
@walnut 我已按要求用
minimal reproducible example更新了问题。很抱歉没有从一开始就这样做。 -
@whitwhoa 我无法在 GCC、Clang 或 MSVC 上使用您的代码重现该错误,请参阅 godbolt.org/z/P88oNz。您正在使用哪些编译器和编译器选项?
-
@walnut 我正在通过 Visual Studio 2017 使用 MSVC。正在使用的唯一选项是
/permissive- /GS,我相信它是默认启用的,/std:c++ latest
标签: c++ reference visual-studio-2017 constants intellisense