gpt4 book ai didi

c++ - Eclipse CDT 索引和 std::unique_ptr

转载 作者:可可西里 更新时间:2023-11-01 17:52:21 26 4
gpt4 key购买 nike

我在这段代码中使用了 std::unique_ptr,它按我预期的方式编译和运行。

std::stringstream out;
out << std::setw(3) << std::setfill('0') << i;
std::unique_ptr<std::string> s(new std::string(out.str()));
s->insert(s->end()-2, 1, '.');
return std::move(s);

但是,我从 Eclipse CDT 收到错误消息。第四行:Method 'insert' could not be resolved, Method 'end' could not be resolved.

以前,我也遇到过出现名称 std::unique_ptr 的错误。这已通过设置预处理器符号 __GXX_EXPERIMENTAL_CXX0X__ 并重建索引来解决,如 this 的答案中所述。问题。

有没有办法让 CDT 明白 s 是 std::string * 类型,并且它应该在 std::string 中查找 s->insert() 和 s->end() ?

PS:我使用的是 Eclipse 3.7.1 和 CDT 8.0.0.201106081058

PS2:我本来想在上面的问题中将其作为评论发布,但我不能,大概是因为我是新用户

最佳答案

似乎 Eclipse CDT 索引器无法推断出也用作 operator->() 返回类型的 unique_ptr::pointer 类型。当你输入类似的东西时你可以看到这个

std::unique_ptr<Type *> ptr;
ptr.reset(new Type);

将“检测到”一个错误,即没有匹配的重载,并且唯一的候选者将是 reset(?)。所以这显然是一个错误。

关于c++ - Eclipse CDT 索引和 std::unique_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8889260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com