在gcc中声明运算符的问题 [英] problems declaring operators in gcc

查看:141
本文介绍了在gcc中声明运算符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友分数& operator + =(const fraction& rhs);


fraction.h(64)错误:错误:''fraction& operator + =(const fraction&)''

必须带两个参数

我几乎把它从C ++书中拉出来(除了朋友)。

有人可以解释为什么GCC在这里给我带来问题吗?

对于+ =或类似的运算符,正确的声明是什么样的

和它的论据是什么?

fraction.h:64:错误:''分数& operator + =(const fraction&)''必须取

正是两个参数

fraction.h:65:错误:''fraction& operator + =(const char *)''必须有一个类或枚举类型的

参数

fraction.h:65:错误:''fraction& operator + =(const char *)''必须使用

正是两个参数

fraction.h:66:错误:''fraction& operator + =(const long int&)''必须有

类或枚举类型的参数

fraction.h:66:error:''fraction& operator + =(const long int&)''必须带

正是两个参数

fraction.h:72:错误:''fraction& operator - =(const fraction&)''必须带

正是两个参数

fraction.h:73:错误:''fraction& operator - =(const char *)''必须有一个类或枚举类型的

参数

fraction.h:73:错误:''fraction& operator - =(const char *)''必须使用

正是两个参数

fraction.h:74:错误:''fraction& operator - =(const long int&)''必须有

类或枚举类型的参数

fraction.h:74:错误:''fraction& operator - =(const long int&)''必须取两个参数



fraction.h:80:错误:''fraction& operator * =(const fraction&)''必须取

正是两个参数

fraction.h:81:错误:''fraction& operator * =(const char *)''必须有一个类或枚举类型的

参数

fraction.h:81:错误:''fraction& operator * =(const char *)''必须使用

正是两个参数

fraction.h:82:错误:''fraction& operator * =(const long int&)''必须有

类或枚举类型的参数

fraction.h:82:错误:''fraction& operator * =(const long int&)''必须取

正是两个参数

fraction.h:88:错误:''fraction& operator / =(const fraction&)''必须取两个参数



fraction.h:89:错误:''fraction& operator / =(const char *)''必须有一个类或枚举类型的

参数

fraction.h:89:错误:''fraction& operator / =(const char *)''必须使用

正是两个参数

fraction.h:90:错误:''fraction& operator / =(const long int&)''必须有

类或枚举类型的参数

fraction.h:90:错误:''fraction& operator / =(const long int&)''必须使用

正是两个参数

fraction.h:96:错误:''fraction&运算符%=(const fraction&)''必须采用

正是两个参数

fraction.h:97:错误:''fraction& operator%=(const char *)''必须有一个类或枚举类型的

参数

fraction.h:97:错误:''fraction& operator%=(const char *)''必须取两个参数



fraction.h:98:错误:''fraction& operator%=(const long int&)''必须有

类或枚举类型的参数

fraction.h:98:error:''fraction&运算符%=(const long int&)''必须使用

正是两个参数

解决方案

Jim Michaels写道:


friend fraction& operator + =(const fraction& rhs);


fraction.h(64)错误:错误:''fraction& operator + =(const fraction&)''

必须带两个参数


我几乎把它从C ++书中拉出来(除了朋友之外) ;)。

有人可以解释为什么GCC在这里给我带来问题吗?

对于+ =或类似的运算符,正确的声明是什么样的

及其参数是什么?



错误说明一切,这些运算符需要两个参数,左边是

和右边表达方式的手边:


lhs + = rhs。


-

Ian Collins。


Ian Collins写道:


Jim Michaels写道:


>朋友分数& operator + =(const fraction& rhs);

fraction.h(64)错误:错误:''fraction& operator + =(const fraction&)''
必须正好用两个参数

我几乎把它从C ++书中拉出来(除了朋友)。
可以有人解释为什么GCC在这里给我带来问题?
对于+ =或类似的运算符,正确的声明是什么样的
以及它的论据是什么?



错误说明了一切,这些操作符需要两个参数,左边是

和表达式的右边:


lhs + = rhs。



朋友分数& operator = =(const fraction&,const fraction&); //没有操作

朋友分数& operator~ =(const fraction&,const char *); //没有操作

朋友分数& operator~ =(const fraction&,const long int&); //没有操作


fraction.h(128)错误:错误:''operator〜''声明为非功能

fraction.h( 129)错误:错误:'const'之前的预期primary-expression

fraction.h(129)错误:错误:预期`)''''const''


我对错误消息感到困惑。这是说我应该这样做吗?


朋友分数&符〜=(); //没有操作

朋友分数&符〜=(); //没有操作

朋友分数&符〜=(); //没有操作

然后我得到

fraction.h(128)错误:错误:在''之前预期的primary-expression'''令牌

fraction.h(128)错误:错误:''operator〜''声明为非功能

我想禁用那些运算符。我可以不使用它们吗?

-


------------------ ------------------

Jim Michaels

发送电子邮件,编辑地址


RAM磁盘*不是*安装方法。


Jim Michaels写道:


Ian Collins写道:


> Jim Michaels写道:


>> friend fraction& operator + =(const fraction& rhs);

fraction.h(64)错误:错误:''fraction& operator + =(const fraction&)''
必须正好用两个参数

我几乎把它从C ++书中拉出来(除了朋友)。
可以有人解释为什么GCC在这里给我带来问题?
对于+ =或类似的运算符,正确的声明是什么样的
以及它的论据是什么?


错误说明一切,这些操作符需要两个参数,左边


lhs + = rhs。



朋友分数& operator = =(const fraction&,const fraction&); //没有操作


我想禁用那些操作符。我可以不使用它们吗?



没有经营者〜=。


-

Ian Collins 。


friend fraction& operator+=(const fraction& rhs);

fraction.h(64) Error: error: ''fraction& operator+=(const fraction&)''
must take exactly two arguments
I practically pulled this out of a C++ book (except for the "friend").
can someone explain why GCC is giving me problems here?
for a += or similar operator, what does a proper declaration look like
and what are its arguments for?
fraction.h:64: error: ''fraction& operator+=(const fraction&)'' must take
exactly two arguments
fraction.h:65: error: ''fraction& operator+=(const char*)'' must have an
argument of class or enumerated type
fraction.h:65: error: ''fraction& operator+=(const char*)'' must take
exactly two arguments
fraction.h:66: error: ''fraction& operator+=(const long int&)'' must have
an argument of class or enumerated type
fraction.h:66: error: ''fraction& operator+=(const long int&)'' must take
exactly two arguments
fraction.h:72: error: ''fraction& operator-=(const fraction&)'' must take
exactly two arguments
fraction.h:73: error: ''fraction& operator-=(const char*)'' must have an
argument of class or enumerated type
fraction.h:73: error: ''fraction& operator-=(const char*)'' must take
exactly two arguments
fraction.h:74: error: ''fraction& operator-=(const long int&)'' must have
an argument of class or enumerated type
fraction.h:74: error: ''fraction& operator-=(const long int&)'' must take
exactly two arguments
fraction.h:80: error: ''fraction& operator*=(const fraction&)'' must take
exactly two arguments
fraction.h:81: error: ''fraction& operator*=(const char*)'' must have an
argument of class or enumerated type
fraction.h:81: error: ''fraction& operator*=(const char*)'' must take
exactly two arguments
fraction.h:82: error: ''fraction& operator*=(const long int&)'' must have
an argument of class or enumerated type
fraction.h:82: error: ''fraction& operator*=(const long int&)'' must take
exactly two arguments
fraction.h:88: error: ''fraction& operator/=(const fraction&)'' must take
exactly two arguments
fraction.h:89: error: ''fraction& operator/=(const char*)'' must have an
argument of class or enumerated type
fraction.h:89: error: ''fraction& operator/=(const char*)'' must take
exactly two arguments
fraction.h:90: error: ''fraction& operator/=(const long int&)'' must have
an argument of class or enumerated type
fraction.h:90: error: ''fraction& operator/=(const long int&)'' must take
exactly two arguments
fraction.h:96: error: ''fraction& operator%=(const fraction&)'' must take
exactly two arguments
fraction.h:97: error: ''fraction& operator%=(const char*)'' must have an
argument of class or enumerated type
fraction.h:97: error: ''fraction& operator%=(const char*)'' must take
exactly two arguments
fraction.h:98: error: ''fraction& operator%=(const long int&)'' must have
an argument of class or enumerated type
fraction.h:98: error: ''fraction& operator%=(const long int&)'' must take
exactly two arguments

解决方案

Jim Michaels wrote:

friend fraction& operator+=(const fraction& rhs);

fraction.h(64) Error: error: ''fraction& operator+=(const fraction&)''
must take exactly two arguments
I practically pulled this out of a C++ book (except for the "friend").
can someone explain why GCC is giving me problems here?
for a += or similar operator, what does a proper declaration look like
and what are its arguments for?

The error says it all, these operators require two arguments, the left
and right hand sides of the expression:

lhs += rhs.

--
Ian Collins.


Ian Collins wrote:

Jim Michaels wrote:

>friend fraction& operator+=(const fraction& rhs);

fraction.h(64) Error: error: ''fraction& operator+=(const fraction&)''
must take exactly two arguments
I practically pulled this out of a C++ book (except for the "friend").
can someone explain why GCC is giving me problems here?
for a += or similar operator, what does a proper declaration look like
and what are its arguments for?

The error says it all, these operators require two arguments, the left
and right hand sides of the expression:

lhs += rhs.

friend fraction& operator~=(const fraction&, const fraction&); //no op
friend fraction& operator~=(const fraction&, const char *); //no op
friend fraction& operator~=(const fraction&, const long int&); // no op

fraction.h(128) Error: error: declaration of ''operator~'' as non-function
fraction.h(129) Error: error: expected primary-expression before ''const''
fraction.h(129) Error: error: expected `)'' before ''const''

I''m confused by the error messages. is this saying I''m supposed to do this?

friend fraction& operator~=(); //no op
friend fraction& operator~=(); //no op
friend fraction& operator~=(); // no op
then I get
fraction.h(128) Error: error: expected primary-expression before '')'' token
fraction.h(128) Error: error: declaration of ''operator~'' as non-function
I want to disable those operators. can I do that by just not using them?
--

------------------------------------
Jim Michaels
for email, edit the address

RAM Disk is *not* an installation method.


Jim Michaels wrote:

Ian Collins wrote:

>Jim Michaels wrote:

>>friend fraction& operator+=(const fraction& rhs);

fraction.h(64) Error: error: ''fraction& operator+=(const fraction&)''
must take exactly two arguments
I practically pulled this out of a C++ book (except for the "friend").
can someone explain why GCC is giving me problems here?
for a += or similar operator, what does a proper declaration look like
and what are its arguments for?

The error says it all, these operators require two arguments, the left
and right hand sides of the expression:

lhs += rhs.

friend fraction& operator~=(const fraction&, const fraction&); //no op

I want to disable those operators. can I do that by just not using them?

There isn''t an operator ~=.

--
Ian Collins.


这篇关于在gcc中声明运算符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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