由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 关于 VC++ vitual, reload 和 derive的一个问题...
相关主题
[合集] protected inheritance in C++工具简单未必是好事-swift
C++ Primer 上关于inheritance protected member 的一段话关于针对接口的unit test
abstract Factory 的困惑各个公司做compiler赚钱吗?
请教struct inside class的问题(C++)老年工程师转行学C++的更新的问题
大牛给介绍一下Objective C vs C++ 的优劣吧实践研究表明,FP代码虫子少,质量高
一个语言差不要紧const int foo()啥意思?
大牛们对Object C有何点评?one question about operator delete
苹果又出新语言了c++ question
相关话题的讨论汇总
话题: add话题: int话题: return话题: public话题: class
进入Programming版参与讨论
1 (共1页)
o******r
发帖数: 259
1
以下程序似乎是对的,在Visual Studio 2005里面却报错:
error C2660: 'B::Add' : function does not take 1 arguments
#include
using namespace std;
class A
{
public:
int Add(int X) {return Add(X, 1);};
private:
virtual int Add(int X, int Y) {return X+Y;};
};
class B: public A
{
private:
int Add(int X, int Y) {return X-Y;};
};
int main()
{
B Obj;
cout << Obj.Add(5);
return 0;
}
难道B不能用base clas A的那个public function吗?
用不同函数名就没问题了
#include
using namespac
P*****f
发帖数: 2272
2
name hiding

以下程序似乎是对的,在Visual Studio 2005里面却报错:
error C2660: 'B::Add' : function does not take 1 arguments
#include
using namespace std;
class A
{
public:
int Add(int X) {return Add(X, 1);};
private:
virtual int Add(int X, int Y) {return X+Y;};
};
class B: public A
{
private:
int Add(int X, int Y) {return X-Y;};
};
int main()
{
B Obj;
cout << Obj.Add(5);
return 0;
}
难道B不能用base clas A的那个public function吗?
用不同函数名就没问题了
#include
u

【在 o******r 的大作中提到】
: 以下程序似乎是对的,在Visual Studio 2005里面却报错:
: error C2660: 'B::Add' : function does not take 1 arguments
: #include
: using namespace std;
: class A
: {
: public:
: int Add(int X) {return Add(X, 1);};
: private:
: virtual int Add(int X, int Y) {return X+Y;};

o******r
发帖数: 259
3
what do you mean?

【在 P*****f 的大作中提到】
: name hiding
:
: 以下程序似乎是对的,在Visual Studio 2005里面却报错:
: error C2660: 'B::Add' : function does not take 1 arguments
: #include
: using namespace std;
: class A
: {
: public:
: int Add(int X) {return Add(X, 1);};

P*****f
发帖数: 2272
4
edited
3.3.7 Name hiding
...
The declaration of a member in a derived class (clause 10) hides the
declaration of a member of a base class of the same name; see 10.2.
4 During the lookup of a name qualified by a namespace name, declarations
that would otherwise be made
visible by a using-directive can be hidden by declarations with the same
name in the namespace containing
the using-directive; see (3.4.3.2).

what do you mean?

【在 o******r 的大作中提到】
: what do you mean?
o******r
发帖数: 259
5
thanks for the info
after goole, the workaround is,
class A
{
public:
int Add(int X) {return Add(X, 1);};
protected:
virtual int Add(int X, int Y) {return X+Y;};
};
class B: public A
{
public:
using A::Add;
private:
int Add(int X, int Y) {return X-Y;};
};

【在 P*****f 的大作中提到】
: edited
: 3.3.7 Name hiding
: ...
: The declaration of a member in a derived class (clause 10) hides the
: declaration of a member of a base class of the same name; see 10.2.
: 4 During the lookup of a name qualified by a namespace name, declarations
: that would otherwise be made
: visible by a using-directive can be hidden by declarations with the same
: name in the namespace containing
: the using-directive; see (3.4.3.2).

N*********y
发帖数: 105
6
Read Effective C++, the item for name-hiding, can't remember the item #,
should be 3X

【在 o******r 的大作中提到】
: 以下程序似乎是对的,在Visual Studio 2005里面却报错:
: error C2660: 'B::Add' : function does not take 1 arguments
: #include
: using namespace std;
: class A
: {
: public:
: int Add(int X) {return Add(X, 1);};
: private:
: virtual int Add(int X, int Y) {return X+Y;};

1 (共1页)
进入Programming版参与讨论
相关主题
c++ question大牛给介绍一下Objective C vs C++ 的优劣吧
C++含有指针成员的类一个语言差不要紧
Questions about MAKEFILE大牛们对Object C有何点评?
有谁读过Design Patterns Explained: A New Perspective on Obj (转载)苹果又出新语言了
[合集] protected inheritance in C++工具简单未必是好事-swift
C++ Primer 上关于inheritance protected member 的一段话关于针对接口的unit test
abstract Factory 的困惑各个公司做compiler赚钱吗?
请教struct inside class的问题(C++)老年工程师转行学C++的更新的问题
相关话题的讨论汇总
话题: add话题: int话题: return话题: public话题: class