gpt4 book ai didi

c++ - 在 boost::variant 中使用 boost::blank 时出现编译器警告

转载 作者:搜寻专家 更新时间:2023-10-31 00:00:31 24 4
gpt4 key购买 nike

我收到以下代码的警告,如果我从变体中删除 boost::blank,该警告就会消失:

namespace DB
{
struct Value{};
struct Container{};
}

typedef boost::variant <boost::blank, DB::Value, DB::Container> CommandData;

struct Command {
explicit Command(CommandData& _data): data(_data){
}

CommandData data;
};

int main()
{
CommandData commandData;
Command command(commandData);
return 0;
}

这是什么问题?

这是警告:

1>: warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
1> c:\boost_1_49_0\boost\variant\variant.hpp(1224) : while compiling class template member function 'boost::variant<T0_,T1,T2>::variant(void)'
1> with
1> [
1> T0_=boost::blank,
1> T1=DB::Value,
1> T2=DB::Container
1> ]
1> c:\code.h(38) : see reference to class template instantiation 'boost::variant<T0_,T1,T2>' being compiled
1> with
1> [
1> T0_=boost::blank,
1> T1=DB::Value,
1> T2=DB::Container
1> ]

最佳答案

这个警告相当愚蠢。 It warns that MSVC现在做正确的事,而不是一些古老的版本。您可以使用 pragma 将其关闭。

关于c++ - 在 boost::variant 中使用 boost::blank 时出现编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13014450/

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