"重载"方法消失了 [英] "Overloaded" method vanished
问题描述
我偶然发现了以下错误
foo.cc:在函数`int main()'':
foo.cc:15:错误:没有匹配函数来调用`Bar :: foo(int)''
foo.cc:9:错误:候选者是: void Bar :: foo(int,int)
其中foo.cc是
struct Foo
{
int i;
void foo(int i){this-> i = i; }
};
struct Bar:public Foo
{
void foo(int j ,int k){this-> i = j * k; }
};
int main()
{
酒吧;
bar.foo(2);
bar.foo(3,4);
返回0;
}
因此在派生类Bar中不再可以访问Foo :: foo(int)。 -
虽然Bar没有foo(int,int)方法但是可以访问它。 - 这个
是否符合标准,如果是这样的话,为什么?
thx& rgds,Steffen
Hi,
I stumbled across the following error
foo.cc: In function `int main()'':
foo.cc:15: error: no matching function for call to `Bar::foo(int)''
foo.cc:9: error: candidates are: void Bar::foo(int, int)
where foo.cc is
struct Foo
{
int i ;
void foo(int i) { this->i = i ; }
} ;
struct Bar : public Foo
{
void foo(int j, int k) { this->i = j * k ; }
} ;
int main()
{
Bar bar ;
bar.foo(2) ;
bar.foo(3, 4) ;
return 0 ;
}
So Foo::foo(int) is no longer accessible in the derived class Bar. --
Though it is accessible if Bar has no foo(int, int) method. -- Is this
covered by the standard, and if so why?
thx & rgds, Steffen
g ++ -v
阅读来自
/usr/local/gcc-3.3的规格。 1 / lib / gcc-lib / alphaev68-dec-osf5.1 / 3.3.1 / specs
配置:../ gcc-3.3.1/configure --prefix = / usr / local /gcc-3.3.1
--disable-shared
线程模型:单个
gcc版本3.3.1
Reading specs from
/usr/local/gcc-3.3.1/lib/gcc-lib/alphaev68-dec-osf5.1/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --prefix=/usr/local/gcc-3.3.1
--disable-shared
Thread model: single
gcc version 3.3.1
推荐答案
Steffen写道:
Steffen wrote:
[snip]
int main()
{
栏吧;
bar.foo(2);
bar.foo(3,4);
返回0;
}
在派生类Bar中不再可以访问Foo :: foo(int)。 -
虽然Bar没有foo(int,int)方法但是可以访问它。 - 这是否符合标准,如果是,为什么?
Hi,
[snip]
int main()
{
Bar bar ;
bar.foo(2) ;
bar.foo(3, 4) ;
return 0 ;
}
So Foo::foo(int) is no longer accessible in the derived class Bar. --
Though it is accessible if Bar has no foo(int, int) method. -- Is this
covered by the standard, and if so why?
是的。它被称为''隐藏功能''。
请在搜索群组存档www.google.com 隐藏功能。
-
Karl Heinz Buchegger
kb ****** @ gascad.at
Yes. It is called ''function hiding''.
Please serach the groups archive at www.google.com for ''function hiding''.
--
Karl Heinz Buchegger
kb******@gascad.at
Thx for the quick回答! - 虽然我必须习惯
背后的想法。
Thx for the quick answer! -- Though I have to get used to the idea
behind.
"斯特芬" < ST **** @ gmx.de>在留言新闻中写道:11 ********************** @ o13g2000cwo.googlegr oups.com ...
"Steffen" <st****@gmx.de> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...
我偶然发现了以下错误
foo.cc:在函数`int main()''中:
foo.cc:15:错误:没有匹配函数调用'Bar :: foo(int)''
foo.cc:9:错误:候选者是:void Bar :: foo(int,int)
其中foo.cc是
struct Foo
{
int i;
void foo(int i){this-> i = i; }
};
struct Bar:public Foo
{
使用Foo :: foo;
// C ++ FAQ LITE,< a rel =nofollowhref =http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23target =_ blank> http://www.parashift.com /c++-faq-lit...ce.html#faq-23 ,问题23.7
void foo(int j,int k){this-> i = j * k ; }
};
int main()
{
酒吧吧;
bar.foo(2);
bar.foo( 3,4);
返回0;
}
因此,派生类Bar中不再可以访问Foo :: foo(int)。 -
虽然Bar没有foo(int,int)方法但是可以访问它。 - 这是否符合标准,如果是,为什么?
thx& rgds,Steffen
Hi,
I stumbled across the following error
foo.cc: In function `int main()'':
foo.cc:15: error: no matching function for call to `Bar::foo(int)''
foo.cc:9: error: candidates are: void Bar::foo(int, int)
where foo.cc is
struct Foo
{
int i ;
void foo(int i) { this->i = i ; }
} ;
struct Bar : public Foo
{ using Foo::foo;
// C++ FAQ LITE, http://www.parashift.com/c++-faq-lit...ce.html#faq-23, Question 23.7
void foo(int j, int k) { this->i = j * k ; }
} ;
int main()
{
Bar bar ;
bar.foo(2) ;
bar.foo(3, 4) ;
return 0 ;
}
So Foo::foo(int) is no longer accessible in the derived class Bar. --
Though it is accessible if Bar has no foo(int, int) method. -- Is this
covered by the standard, and if so why?
thx & rgds, Steffen
g ++ -v
阅读来自
/usr/local/gcc-3.3.1/lib/gcc-lib/的规格alphaev68-dec-osf5.1 / 3.3.1 / specs
配置:../ gcc-3.3.1/configure --prefix = / usr / local / gcc-3.3.1
- 禁用共享
线程模型:单个
gcc版本3.3.1
Reading specs from
/usr/local/gcc-3.3.1/lib/gcc-lib/alphaev68-dec-osf5.1/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --prefix=/usr/local/gcc-3.3.1
--disable-shared
Thread model: single
gcc version 3.3.1
-
Alex Vinokur
email:alex DOT vinokur AT gmail DOT com
http:/ /mathforum.org/library/view/10978.html
http: //sourceforge.net/users/alexvn
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
这篇关于"重载"方法消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!