如何防止基类中的函数从子类重载 [英] How to prevent a function in base class being overloaded from child class

查看:94
本文介绍了如何防止基类中的函数从子类重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题与主题一样。


例如:


class BaseClass {

public:

void func(){做某事; } //我不希望这个函数在其继承的类中重载



};


class ChildClass: BaseClass {

public:

void func(){do otherthing; } //这应该被禁止当

编译

}

Question is as in subject.

For example:

class BaseClass {
public:
void func() { do something; } // I don''t want this function being
overloaded in its inherited class
};

class ChildClass : BaseClass {
public:
void func() { do otherthing; } // this should be inhibited when
compiling
}

推荐答案



" modemer" < me@privacy.net.invalid>在消息中写道

news:d1 ********** @ domitilla.aioe.org ...

"modemer" <me@privacy.net.invalid> wrote in message
news:d1**********@domitilla.aioe.org...
问题与主题一样。

例如:

类BaseClass {
public:
void func(){做某事; } //我不希望这个函数在其继承的类中重载
};

类ChildClass:BaseClass {
public:
void func(){do otherthing; } //这应该被禁止当


对不起,错字,应该是:禁止

编译
}
Question is as in subject.

For example:

class BaseClass {
public:
void func() { do something; } // I don''t want this function being
overloaded in its inherited class
};

class ChildClass : BaseClass {
public:
void func() { do otherthing; } // this should be inhibited when
sorry, typo, should be: prohibited
compiling
}



modemer写道:
modemer wrote:
问题与主题一样。

例如:
class BaseClass {
public:
void func(){做某事; } //我不希望这个函数在其继承的类中重载
};

类ChildClass:BaseClass {
public:
void func(){do otherthing; } //这应该在编译时被禁止
}
Question is as in subject.

For example:

class BaseClass {
public:
void func() { do something; } // I don''t want this function being
overloaded in its inherited class
};

class ChildClass : BaseClass {
public:
void func() { do otherthing; } // this should be inhibited when
compiling
}




''ChildClass :: func''不会重载''BaseClass: :FUNC'。来自基类的''func''

名称是派生类''成员的_hidden_​​。


也许当你了解事情如何运作时,你不需要你要求的预防

。您认为您将通过阻止您所谓的重载来解决什么特别的问题?


V



The ''ChildClass::func'' does not overload ''BaseClass::func''. The ''func''
name from the base class is _hidden_ by the derived class'' member.

Perhaps when you learn how things work, you won''t need the "prevention"
you ask about. What particular problem do you think you''re going to
solve by preventing what you call "overloading"?

V


Victor Bazarov写道:
Victor Bazarov wrote:

也许当你了解事情如何运作时,你不需要预防
你问关于。您认为通过阻止您所谓的重载来解决什么特殊问题?

Perhaps when you learn how things work, you won''t need the "prevention"
you ask about. What particular problem do you think you''re going to
solve by preventing what you call "overloading"?




派生类设计师的问题尝试使用基类设计师没有想到的技术来解决基类设计者很少或根本不知道的问题。

问题。 br />
另请参阅:如何强制所有派生类(无论多远程),

覆盖此函数, 我怎样才能阻止任何人从这个类中获得
,和我怎样才能让每个人都做我认为最适合他们的事情。


-


Pete Becker
Dinkumware,Ltd。( http://www.dinkumware.com



The problem of a derived class designer trying to solve problems in a
problem domain that the base class designer knows little or nothing
about, using techniques that the base class designer didn''t think of.
See also: "How can I force all derived classes, however remote, to
override this function," "How can I prevent anyone from deriving from
this class," and "How can I make everyone do what I know is best for them."

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)


这篇关于如何防止基类中的函数从子类重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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