在 Visual Studio 2012 中使用“= delete”时出现编译器错误
Compiler error when using "= delete" in Visual Studio 2012
我有这个 class,编译时会给出 C2059 和 C 2238 ';'两条线上的两个错误。为什么这段代码无法编译?
class bitreader
{
std::istream& §is;
std::uint8_t §buff;
int §n;
uint32_t read()
{
if (§n == 0) {
§buff = §is.get();
§n = 8;
}
§n--;
return (§buff >> §n) & 1;
}
public:
bitreader(std::istream& os)
: §is(os)
, §n(0)
{}
// The following two lines produce errors
bitreader(const bitreader& rhs) = delete;
bitreader& operator=(const bitreader& rhs) = delete;
uint32_t operator()(uint32_t n)
{
uint32_t val = 0;
while (n-- > 0)
val = (val << 1) | read();
return val;
}
std::istream& operator()(uint32_t& val, uint32_t n)
{
val = 0;
while (n-->0)
val = (val << 1) | read();
return §is;
}
};
我补充说同样的代码在我朋友的 Visual Studio 上编译没有任何问题。注意:如果我注释代码编译的行。
The =delete
specifier is a C++11 feature that Visual Studio 2012 does not support。要么将您的 Visual Studio 升级到更新的版本,要么删除 =delete
并将这两个声明设为私有。
我有这个 class,编译时会给出 C2059 和 C 2238 ';'两条线上的两个错误。为什么这段代码无法编译?
class bitreader
{
std::istream& §is;
std::uint8_t §buff;
int §n;
uint32_t read()
{
if (§n == 0) {
§buff = §is.get();
§n = 8;
}
§n--;
return (§buff >> §n) & 1;
}
public:
bitreader(std::istream& os)
: §is(os)
, §n(0)
{}
// The following two lines produce errors
bitreader(const bitreader& rhs) = delete;
bitreader& operator=(const bitreader& rhs) = delete;
uint32_t operator()(uint32_t n)
{
uint32_t val = 0;
while (n-- > 0)
val = (val << 1) | read();
return val;
}
std::istream& operator()(uint32_t& val, uint32_t n)
{
val = 0;
while (n-->0)
val = (val << 1) | read();
return §is;
}
};
我补充说同样的代码在我朋友的 Visual Studio 上编译没有任何问题。注意:如果我注释代码编译的行。
The =delete
specifier is a C++11 feature that Visual Studio 2012 does not support。要么将您的 Visual Studio 升级到更新的版本,要么删除 =delete
并将这两个声明设为私有。