473,801 Members | 2,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

virtual inheritance problem with class template specializations

As the comments of the following C++ code,
I got the ambiguous error in the specialized class " PThreadTimer<vo id *(*)(void *)> ".
I performed the virtual inheritance mechanism on its base classes : "PThreadBas e" and "PThread<> ",
and then the derived template class "PThreadTim er< >" could pass the compilation without any ambiguous errors.
But it's occured in the specialized class " PThreadTimer<vo id *(*)(void *)> ".

Why are the ambiguous errors only occured in the specilized class?

My compiler is gcc 3.3.3 [FreeBSD] 20031106, Thanks a lot.

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
class PThreadTimerBas e : public virtual PThreadBase {
[Deleted]
};

template <typename Type = void *(*)(void *)>
class PThreadTimer : public PThread<Type>, public PThreadTimerBas e {
private:
typedef void *(Type::*FPType )(void *);

static void *Call(void *obj)
{
[Deleted]
/*
* >>>>>>>>>> There are not any ambiguous occured. <<<<<<<<<<<<
*/
(static_cast<PT hreadTimer<Type > *>(obj)->StartObject->*static_cast<P ThreadTimer<Typ e>
*>(obj)->Star
tRoutine)(stati c_cast<PThreadT imer<Type> *>(obj)->RoutineArgs) ;
[Deleted]
}
[Deleted]
};

template<> class PThreadTimer<vo id *(*)(void *)> :
public PThread<void *(*)(void *)>, public PThreadTimerBas e {
private:
typedef void *(*FPType)(void *);

static void *Call(void *obj)
{
[Deleted]

/*
* error: request for member `RoutineArgs' is ambiguous
* candidates are: void*PThreadBas e::RoutineArgs
* void*PThreadBas e::RoutineArgs
*/
static_cast<PTh readTimer<FPTyp e> *>(obj)->StartRoutine(s tatic_cast<PThr eadTimer<FPType >
*>(obj)->Ro
utineArgs);
[Deleted]
}
[Deleted]
};
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
class PThreadBase {
protected:
[Deleted]
PThreadState State;
void *RoutineArgs;
void *RoutineResults ;
[Deleted]
};

template <typename Type = void *(*)(void *)>
class PThread : public virtual PThreadBase {
protected:
[Deleted]
Type *StartObject;
FPType StartRoutine;
[Deleted]
};

template<> class PThread<void *(*)(void *)> : public PThreadBase {
protected:
[Deleted]
typedef void *(*FPType)(void *);

FPType StartRoutine;
[Deleted]
}
Jul 22 '05 #1
0 1380

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

Similar topics

5
4486
by: SainTiss | last post by:
Hi, Is there an extra overhead in using virtual functions and templates? Or is is just the same overhead as with regular classes? Either way, if you'd want to avoid it, will you always end up with code duplication? For example: let's say you've got two template specializations, which differ only slightly... So you put the common behaviour in a
4
4630
by: Xavier | last post by:
Hi, I have a question, in a "dreaded diamond" situation, regarding the following code: ---- Begin code #include <iostream> using namespace std;
11
1933
by: Matthias | last post by:
Hello, templated virtual member functions are not allowed. Now I am searching for a good workaround for this problem, but I can't find any. Here's my problem: class Base { template <typename T> virtual void setParam(std::string s, const T& value);
1
1489
by: Imre | last post by:
Hi I'd like to create a special cast template function that can be used to cast a base pointer to a derived one, and uses dynamic_cast if virtual inheritance is involved, and static_cast otherwise. Unfortunately I don't know how to properly detect VI. I've seen a trick for detecting VI, that goes something like: template <class B, class D> struct IsVirtualBaseAndDerived
4
2347
by: Stefan Nikolaus | last post by:
Hello, I've run into problems with defining a template, which inherits from a base template and the usage of virtual methods in those. I want to initialize a member variable depending on which template is created and I tried to define a virtual method, that's called from the base template ctor. Here's my example code: #include <iostream>
11
3438
by: Nindi73 | last post by:
A few days a ago I posted my code for a deep copy pointer which doesn't require the pointee object to have a virtual copy constructor. I need help with checking that it was exception safe and exception neutral/ I got a reply from Bux with his code for a smart pointer with far fewer lines of code and more cleaner design, not over engineered like mine. ...
5
1991
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary, not to get polymorphic behavior. None of them has virtual methods, and are self contained (no destructor at all) thus do not have a chance to have memory error. Thus the derived classes has additional functionality, not additional data.
7
2121
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from BufferBase, and customized in order to be able to a type of data (of any kind, such as chunks of audio samples from a sound card). The processor classes are derived from ProcessorBase, and are customized to handle BufferBase-derived objects. Each...
12
2387
by: Massimo | last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance hierarchy, and I'd like to know what the standard says about it and if my compiler is correct in what it does. I have two consecutive layers of diamond-shaped inheritance; the first layer is declared as using virtual inheritance, while the second one is declared as *not* using it. This is what I'd like to have:
0
9558
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,...
0
10298
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
10277
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
9105
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...
0
6833
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();...
0
5489
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...
0
5619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2963
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.