编译错误 [英] compilation error

查看:92
本文介绍了编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点惊讶,以下没有编译


#inclue< algorithm>

enum {C = 10};

int main()

{

char a [C];

std :: fill_n(a,C,'' \0'');

}


错误信息指向std :: fill_n的实现并抱怨


一元'' - '':''''没有定义此运算符或转换为预定义运算符可接受的类型



基本上我认为它抱怨它不能修改

枚举的价值。


这是正确的吗?我希望模板可以使用int

进行实例化,可以使用operator--进行修改。


替换枚举{C = 10};用const int C = 10;编译。


John

Slightly surprised that the following didn''t compile

#inclue <algorithm>
enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, C, ''\0'');
}

Error message points to implementation of std::fill_n and complains that

unary ''--'' : '''' does not define this operator or a conversion to a type
acceptable to the predefined operator

Essentially I think its complaining that it can''t modify the value of the
enum C.

Is this correct? I expected the template to be instantiated with an int
which could be modified using operator--.

Replacing enum { C = 10 }; with const int C = 10; does compile.

John

推荐答案




开2003年7月15日星期二,John Harrison写道:


On Tue, 15 Jul 2003, John Harrison wrote:
稍微惊讶一下,以下没有编译

#inclue< algorithm>
enum {C = 10};
int main()
{char a [C];
std :: fill_n(a,C,''\''' );
}

错误信息指向std :: fill_n的实现并抱怨

一元''''':''''不会定义此运算符或转换为预定义运算符可接受的类型

基本上我认为它抱怨它不能修改
枚举C的值。 br />
这是对的吗?我希望模板可以用int
实例化,可以使用operator修改。

替换枚举{C = 10};用const int C = 10;编译。

John
Slightly surprised that the following didn''t compile

#inclue <algorithm>
enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, C, ''\0'');
}

Error message points to implementation of std::fill_n and complains that

unary ''--'' : '''' does not define this operator or a conversion to a type
acceptable to the predefined operator

Essentially I think its complaining that it can''t modify the value of the
enum C.

Is this correct? I expected the template to be instantiated with an int
which could be modified using operator--.

Replacing enum { C = 10 }; with const int C = 10; does compile.

John



你的代码,如上所述,用gcc 3.2.2编译。您是否使用fill()

而不是fill_n()?


Your code, as above, compiles, as is, with gcc 3.2.2. Did you use fill()
instead of fill_n()?




" Jesse Nowells" < JN ****** @ transbay.net>在消息中写道

新闻:Pine.BSF.4.31.0307150053130.80673-100000@localhost ...

"Jesse Nowells" <jn******@transbay.net> wrote in message
news:Pine.BSF.4.31.0307150053130.80673-100000@localhost...


2003年7月15日星期二,约翰哈里森写道:


On Tue, 15 Jul 2003, John Harrison wrote:
稍微惊讶以下没有编译

#inclue< algorithm>
enum {C = 10} ;
int main()
{char a [C];
std :: fill_n(a,C,''\''');
}

错误消息指向std :: fill_n的实现并抱怨

一元'' - '':''''没有定义此运算符或转换对于预定义操作员可接受的类型

基本上我认为它抱怨它不能修改
的值枚举C.
这是对的吗?我希望模板可以用int
实例化,可以使用operator修改。

替换枚举{C = 10};用const int C = 10;编译。

John
Slightly surprised that the following didn''t compile

#inclue <algorithm>
enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, C, ''\0'');
}

Error message points to implementation of std::fill_n and complains that

unary ''--'' : '''' does not define this operator or a conversion to a type
acceptable to the predefined operator

Essentially I think its complaining that it can''t modify the value of the enum C.

Is this correct? I expected the template to be instantiated with an int
which could be modified using operator--.

Replacing enum { C = 10 }; with const int C = 10; does compile.

John



你的代码,如上所述,用gcc 3.2.2编译。您是否使用fill()
而不是fill_n()?


Your code, as above, compiles, as is, with gcc 3.2.2. Did you use fill()
instead of fill_n()?




我没有使用与上面完全相同的代码,从我的编译器剪切和粘贴,除了

#include< algorithm>我设法输入错误。


编译器是VC ++ .NET


john



No I used code exactly as above, cut and paste from my compiler, except for
#include <algorithm> which I managed to mistype.

Compiler is VC++ .NET

john




" Alf P. Steinbach" <人*** @ start.no>在消息中写道

news:3f **************** @ News.CIS.DFN.DE ...

"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
On星期二,2003年7月15日08:03:01 +0100,约翰哈里森
< jo ************* @ hotmail.com>写道:
On Tue, 15 Jul 2003 08:03:01 +0100, "John Harrison" <jo*************@hotmail.com> wrote:
有点惊讶,以下没有编译

#inclue<算法>
哈,你的罪魁祸首就在那里。 ; - )
Slightly surprised that the following didn''t compile

#inclue <algorithm>
Hah, there''s your culprit right there. ;-)




剩下的代码是剪切和粘贴的,我发誓!



The rest of the code was cut and paste, I swear!

enum { C = 10};
int main()
{char a [C];
std :: fill_n(a,C,''\''');
}

错误信息指向std :: fill_n的实现并抱怨

一元'' - '':''''没有定义这个操作员或转换为预定义操作员可接受的类型
enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, C, ''\0'');
}

Error message points to implementation of std::fill_n and complains that

unary ''--'' : '''' does not define this operator or a conversion to a type
acceptable to the predefined operator



enum E {C = 10};

E操作员 - (E x){return static_cast< E>(x-1); }


enum E{ C = 10 };

E operator--( E x ){ return static_cast<E>( x-1 ); }

基本上我认为它抱怨它不能修改
枚举C的值。
Essentially I think its complaining that it can''t modify the value of the
enum C.



不。它抱怨枚举类型没有减量运算符。



Nope. It complains that enum type doesn''t have a decrement operator.




所以这可能也会编译(没有我的编译器方便

check)


enum {C = 10};

int main()

{

char a [C];

std :: fill_n(a,(int)C,''\ 0'');

}


john



So presumably this would also compile (don''t have my compiler handy to
check)

enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, (int)C, ''\0'');
}

john


这篇关于编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆