通过const引用传递矢量时出现智能错误(但项目构建)

问题描述 投票:0回答:1

[尝试通过const引用传递矢量时,我收到以下智能感知错误(项目成功构建:):

no instance of constructor "ObjOne::ObjOne" matches the argument list
argument types are: (std::vector<int, std::allocator<int>>) 

enter image description here

我在下面的最小可复制示例中评论了发生错误的情况。在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;
}
c++ reference visual-studio-2017 const intellisense
1个回答
0
投票
通过常量引用传递矢量时出现智能错误(但项目构建)

我已经在最新的VS2017中测试了您的样本,并且

Intellisense可以正常工作。因此,我想知道您的VS环境和Intellisnese是否存在一些问题。

我的环境

-操作系统:win10 1903 VS:VS2017 Community 19.9.20您可以尝试我的建议来解决您的问题:

作为建议

,如果您的VS2017不是最新版本,则可以将其更新为可能具有较新修补程序的最新版本。

[1)

关闭VS实例,删除.vs隐藏文件夹,bin文件夹和obj文件夹

2)

清理C:\ Users \ user \ AppData \ Local \ Microsoft \ VisualStudio \ 15.0_xxxxx \ ComponentModelCache下的VS组件缓存

3]

在VS中打开项目,然后右键单击项目-> Properties-> C/C++-> Language->将C++ Language Standard设置为ISO C++ 17 Standard(/std:c++17)] >

另外

,如果这些方法不起作用,请在VS Installer中尝试do a repair,以防智能感知器损坏。
希望它可以帮助您。
© www.soinside.com 2019 - 2024. All rights reserved.