473,412 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Smart Pointers and virtual

Hi,

I am trying to modify existing code to use smart pointers and I get some
issues with virtual methods :

class Folder : public Object
{
public:
friend class PimItemCollection;
friend class ContactCollection;
friend class TaskCollection;
friend class AppointmentCollection;

// Constructor/destructor
Folder(OutlookSession* pOutlookSession) = 0;
virtual ~Folder();

virtual RefPtr<PimItemCollectionget_Items();

protected:
....
};

class ContactFolder : public Folder
{
public:
// Constructor/destructor
ContactFolder(OutlookSession* pOutlookSession);
ContactFolder();

virtual ~ContactFolder();

virtual RefPtr<ContactCollectionget_Items();
};

1>c:\testpoom\System.WindowsMobile.PocketOutlook.h (640) : error C2555:
'System::WindowsMobile::PocketOutlook::ContactFold er::get_Items':
overriding virtual function return type differs and is not covariant
from 'System::WindowsMobile::PocketOutlook::Folder::get _Items'

I Don't understand the error because ContactCollection is inheriting
from PimItemCollection.


Aug 18 '08 #1
1 2061
mosfet wrote:
Hi,

I am trying to modify existing code to use smart pointers and I get some
issues with virtual methods :

class Folder : public Object
{
public:
friend class PimItemCollection;
friend class ContactCollection;
friend class TaskCollection;
friend class AppointmentCollection;

// Constructor/destructor
Folder(OutlookSession* pOutlookSession) = 0;
virtual ~Folder();

virtual RefPtr<PimItemCollectionget_Items();

protected:
...
};

class ContactFolder : public Folder
{
public:
// Constructor/destructor
ContactFolder(OutlookSession* pOutlookSession);
ContactFolder();

virtual ~ContactFolder();

virtual RefPtr<ContactCollectionget_Items();
};

1>c:\testpoom\System.WindowsMobile.PocketOutlook.h (640) : error C2555:
'System::WindowsMobile::PocketOutlook::ContactFold er::get_Items':
overriding virtual function return type differs and is not covariant
from 'System::WindowsMobile::PocketOutlook::Folder::get _Items'

I Don't understand the error because ContactCollection is inheriting
from PimItemCollection.
Unfortunately this is a problem with smart pointers in replacing raw
pointers.

When overrriding virtual functions one can modify the result type in
the override to a derived class of the return in the interface class,
known as covariant return. Unfortunately this doesnt translate if you
change to smart pointer as smart pointer to derived is not a derived
class of smart pointer to base (though it is convertible), but is a
separate class, so there is no covariant mechanism.

All you can do is change sig to base class, smart pointer return
expression in body should be automatically converted , but you then may
have to downcast again at other places in code, if you use derived class
direct, though myself I have found this rare in practise. Perhaps
covariant return is a case of being too clever anyway, breaks encapsulation

regards
Andy Little
Aug 18 '08 #2

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

Similar topics

1
by: Shiva | last post by:
I saw C++ FAQ LITE on how to go about creating a smart pointer. I tried my hand at creating a smart pointer using templates. I'm thinking of creating just one Pointer class to create pointers for...
2
by: Hendrik Schober | last post by:
Hi, I need something like this: class X { private: struct Impl_ { virtual ~Impl_() {} virtual Impl_* clone() const = 0; };
8
by: Axter | last post by:
I normally use a program call Doxygen to document my source code.(http://www.stack.nl/~dimitri/doxygen) This method works great for small and medium size projects, and you can get good...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
7
by: Steven T. Hatton | last post by:
I have a couple questions about the design pattern presented in the example quoted below. I can appreciate why the destructor is protected, but why is it not virtual? I am forced to assume that I...
3
by: mati-006 | last post by:
Hi, I think the code will be the best way to explain what I mean: #include "arglib/arg_shared.h" class base { public: base() {} virtual ~base() {} };
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
1
by: Rune Allnor | last post by:
Hi all. I am sure this is an oldie, but I can't find a useful suggestion on how to solve it. I have a class hierarchy of classes derived from a base class. I would like to set up a vector of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.