class Base {
public:
void t1() {}
void t2() {}
void t3() {};
};
class Derived : public Base
{
public:
private:
using Base::t1;
using Base::t3;
};
Derived d;
d.t1(); // error, this is what I want
d.t3(); // error, this is what I want
d.Base::t1(); // ok <== I don't want user call method this way
my question:
I don't want user to call t1(); and t3(); from class Derived
Is there any way? 6 4281
Peter Lee wrote:
class Base {
public:
void t1() {}
void t2() {}
void t3() {};
};
class Derived : public Base
{
public:
private:
using Base::t1;
using Base::t3;
};
Derived d;
d.t1(); // error, this is what I want
d.t3(); // error, this is what I want
d.Base::t1(); // ok <== I don't want user call method this way
my question:
I don't want user to call t1(); and t3(); from class Derived
Is there any way?
There's nothing to stop them doing
Base& b(d);
b.t1();
why do you want to do this?
--
Ian Collins.
Ian Collins ¼g¹D¡G
I just wanto to disable Derived object call t1(); and t3();
so this way is OK
Base& b(d);
b.t1();
somethimes I want to inherit Base class that has many method
but some Base class's method I don't want it ( the reason is maybe I
think those method is NOT good or NOT safe .. etc)
If I use the following way, it's waste time to copy and paste when Base
class has many method
But I just don't want some of them
class D
{
public:
void t2() { m_base.t2(); }
private:
Base m_base;
};
Peter Lee wrote:
class Base {
public:
void t1() {}
void t2() {}
void t3() {};
};
class Derived : public Base
{
public:
private:
using Base::t1;
using Base::t3;
};
Derived d;
d.t1(); // error, this is what I want
d.t3(); // error, this is what I want
d.Base::t1(); // ok <== I don't want user call method this way
my question:
I don't want user to call t1(); and t3(); from class Derived
Is there any way?
There's nothing to stop them doing
Base& b(d);
b.t1();
why do you want to do this?
--
Ian Collins.
Peter Lee wrote:
Ian Collins ¼g¹D¡G
Please don't top-post.
>>Peter Lee wrote:
>>>my question: I don't want user to call t1(); and t3(); from class Derived Is there any way? There's nothing to stop them doing
Base& b(d); b.t1();
why do you want to do this?
I just wanto to disable Derived object call t1(); and t3();
so this way is OK
Base& b(d);
b.t1();
somethimes I want to inherit Base class that has many method
but some Base class's method I don't want it ( the reason is maybe I
think those method is NOT good or NOT safe .. etc)
If I use the following way, it's waste time to copy and paste when Base
class has many method
But I just don't want some of them
Sounds a bit of a design smell to me. If that's what you want, make
them private in Base and public in Derived.
--
Ian Collins.
Ian Collins ¼g¹D¡G
Peter Lee wrote:
Ian Collins ¼g¹D¡G
Please don't top-post.
>Peter Lee wrote:
>>my question: I don't want user to call t1(); and t3(); from class Derived Is there any way?
There's nothing to stop them doing
Base& b(d);
b.t1();
why do you want to do this?
I just wanto to disable Derived object call t1(); and t3();
so this way is OK
Base& b(d);
b.t1();
somethimes I want to inherit Base class that has many method
but some Base class's method I don't want it ( the reason is maybe I
think those method is NOT good or NOT safe .. etc)
If I use the following way, it's waste time to copy and paste when Base
class has many method
But I just don't want some of them
Sounds a bit of a design smell to me. If that's what you want, make
them private in Base and public in Derived.
--
Ian Collins.
Base class is not mine... it's maybe a system class framework...
Peter Lee wrote:
Ian Collins ¼g¹D¡G
>>Peter Lee wrote:
>>>If I use the following way, it's waste time to copy and paste when Base class has many method But I just don't want some of them Sounds a bit of a design smell to me. If that's what you want, make them private in Base and public in Derived.
Base class is not mine... it's maybe a system class framework...
The make it a private base of Derived and expose the methods you want
through Derived.
--
Ian Collins.
Peter Lee wrote:
d.t1(); // error, this is what I want
d.t3(); // error, this is what I want
d.Base::t1(); // ok <== I don't want user call method this way
my question:
I don't want user to call t1(); and t3(); from class Derived
Is there any way?
class Derived : protected Base
{
public:
using Base::t2;
}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gene Vital |
last post by:
C#
I am trying to figure out how to disable the Tab key in a TextBox.I need
to prevent the user from leaving the TextBox unless the data was entered
correctly, any pointers?
|
by: Peter Oliphant |
last post by:
Is there a way of defining a method in a base class such that derived
classes will call their own version, EVEN if the derived instance is
referred to by a pointer to the base class? Note that the base class method
is not to be abstract, and will be called if the instance was created as a
'generic' base class instance.
It's sort of like I want the method to be abstract to children, but concrete
at the base level. That way I can refer to...
|
by: Andy |
last post by:
Hi all,
I have a site with the following architecture:
Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
|
by: relient |
last post by:
Question: Why can't you access a private inherited field from a base
class in a derived class? I have a *theory* of how this works, of
which, I'm not completely sure of but makes logical sense to me. So,
I'm here for an answer (more of a confirmation), hopefully.
First let me say that I know people keep saying; it doesn't work
because the member "is a private". I believe there's more to it than
just simply that...
Theory: You inherit,...
|
by: Dennis Jones |
last post by:
Hello,
I have a couple of classes that look something like this:
class RecordBase
{
};
class RecordDerived : public RecordBase
{
| |
by: nyathancha |
last post by:
Hi,
How Do I create an instance of a derived class from an instance of a
base class, essentially wrapping up an existing base class with some
additional functionality. The reason I need this is because I am not
always able to control/create all the different constructors the base
class has. My problem can be described in code as follows ...
/* This is the base class with a whole heap of
constructors/functionality*/
public class Animal
|
by: bryanbabula |
last post by:
I have a question about overriding i was wondering if anyone could
help me with, or even suggesting a better/different way. I have no
idea if this can even be done or not.
I was wondering if there was anyway to force a class to call a base
class's method that it is overriding? Almost the same way you have to
call a base class's constructor if it has arguments.
(example ** assuming the Person class's constructor has (string
FirstName) as...
|
by: bhanubalaji |
last post by:
hi,
I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA..
can any one help regarding this..
What's the wrong with my code?
I am sending my code here..
Thanks in Advance...
Regards
|
by: =?Utf-8?B?cmFtbzk5NDE=?= |
last post by:
Hi,
Is there any way disable using "protected override void OnPaint(..." method
out of the assembly. I create usercontrol and i do not want user adds extra
codes OnPaint method for securtity purpose. And i don't give a permission to
call "CreateGraphics()".
Thanks your responses.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |