473,657 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Derived::Derive d(const Base&) and Derived& operator=(const Base&)

Hi folks,

Can somebodyshed some light on this problem?

class Interface {
protected:
Interface() { ...}
virtual ~Interface() { ... }

public:
virtual method() = 0;
}

class Impl1: public Interface {
public:
Impl() { ... }
Impl(const Interface&); // problem 1
virtual ~Impl() { ... }
Impl& operator=(const Interface&); // problem 2
virtual method() { ... }
}

The problem is that the compiler (VC 2005) insists on generating
Impl1(const Impl1&) // copy constructor
and
Impl& operator=(const Impl1&) // default assignment operator

The problem is I do not want these methods. I want any Impl to be
able to construct/assign itself from any (other) Impl satisfying the
Interface. That's the whole point of having an Interface. I
shouldn't need these methods. The compiler should be able to use my
methods since every Impl is also an Interface, no?

Thanks,
J.

May 22 '07 #1
1 2114
The problem is that the compiler (VC 2005) insists on generating
Impl1(const Impl1&) // copy constructor
and
Impl& operator=(const Impl1&) // default assignment operator

The problem is I do not want these methods.
Declare them private and do not provide an implementation:

class Impl1: public Interface
{
private:
Impll(const Impll& copy); // Not implemented.
Impll& operator(const Impll& copy); // Not implemented.

<<STUFF>>
};
May 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8257
by: Victor Irzak | last post by:
Hello, I have an ABC. it supports: ostream & operator << I also have a derived class that supports this operator. How can I call operator << of the base class for derived object??? Is it at all possible?
10
2506
by: placid | last post by:
Hi all, I was just wondering, in Java there is an operator called instanceOf, whats the equivalent in c++? Thanks in advance to all.
2
2175
by: TonyM | last post by:
Q: Is there a good way to overcome this apparent bug without modifying the mfc code? ___________________________________ Info: Although it is NOT a good idea, I seemed to have perhaps located a bug in this function with the GetLength call whose results are sent to the sub-call to Concatenate. So I added the following and it asserts on particular strings that are used. (I am not sure if this makes any difference, but I am using class...
12
3784
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. 1. The Deserialization goes like: #Region " Load "
2
7391
by: Tom Smith | last post by:
I'm having difficulty with overloading ==, and it's making my brain melt - can you help...? What I want to have is: 1) A base class A with virtual operator== defined (no problem) 2) A class B derived from A with operator== overridden (again, no problem) 3) Pointers A* b1, b2 which may actually point to instances of B, where I can call (*b1)==(*b2) and have it use the overridden form of == found in B. Having written this all out I'm...
6
2032
by: AzizMandar | last post by:
There is probably a better way to do this and if so I'm just as happy to see that way. I have a program where I have factories that each create various objects abstracted from a base class. The Factories all have a base class as well for the objects to point back to. So I have
3
2121
by: Nindi73 | last post by:
Hi, I am in need of a deep copy smart pointer (Boost doesn't provide one) which doesnt require the contained types to have a virtual copy constructor. I wrote a smart pointer class that I think meets these requirements, but after reading the chapter on exceptions in 'Exceptional C++':Sutter, I am not sure if its is really Exception safe or Exception Neutral. I suppose putting the theory in that chapter into practice isn't trivial.
4
2178
by: developereo | last post by:
Hi folks, Can anybody shed some light on this problem? class Interface { public: Interface() { ...} virtual ~Interface() { ...} virtual method() = 0; };
1
327
by: developereo | last post by:
Hi folks, Can somebody shed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
0
8407
marktang
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...
0
8739
jinu1996
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...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
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...
0
7347
agi2029
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...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.