我有一些可以在gcc 4.9中编译的东西,但在gcc 4.7中失败了。
这是一个具有移动构造函数的类,但我将其复制构造函数设置为私有:
class Option
{
public:
Option(const std::string& name_long,
char name_short,
const std::string& group,
bool* value_store,
int32_t flags,
const std::string& option_desc);
// and several similar constructors
Option(Option&& other);
private:
Option(const Option& other);
};
问题出现在向量的
emplace_back()
函数中调用时:// options is a std::vector<Option>
options.emplace_back("help", 'h', OPTION_GROUP_MISC,
&opt_show_help, htio2::Option::FLAG_NONE,
"Show help and exit.");
这段代码可以通过gcc 4.9成功编译且运行良好,但是在gcc 4.7下会出现一个两屏幕长的错误提示,称其复制构造函数为私有:
In file included from /public/yx/works/writing_tcrklass2/src/TCRklass2-1.90.0-Source/src/tcrk2/App.h:4:0,
from /public/yx/works/writing_tcrklass2/src/TCRklass2-1.90.0-Source/src/tcrk2/App.cpp:1:
......
/public/yx/works/writing_tcrklass2/src/TCRklass2-1.90.0-Source/src/tcrk2/App.cpp:58:47: required from here
/usr/local/include/htio2/OptionParser.h:188:5: error: ‘htio2::Option::Option(const htio2::Option&)’ is private
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/move.h:57:0,
......
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/type_traits:762:43: error: within this context
作为我的一些用户使用的是非常老旧的系统,很可能使用旧版编译器,我真的想知道是否有任何方法可以解决这个问题。
is_copy_constructible
特性会产生错误。 - Jonathan Wakely