473,396 Members | 2,026 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,396 software developers and data experts.

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<void *(*)(void *)> ".
I performed the virtual inheritance mechanism on its base classes : "PThreadBase" and "PThread<> ",
and then the derived template class "PThreadTimer< >" could pass the compilation without any ambiguous errors.
But it's occured in the specialized class " PThreadTimer<void *(*)(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 PThreadTimerBase : public virtual PThreadBase {
[Deleted]
};

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

static void *Call(void *obj)
{
[Deleted]
/*
* >>>>>>>>>> There are not any ambiguous occured. <<<<<<<<<<<<
*/
(static_cast<PThreadTimer<Type> *>(obj)->StartObject->*static_cast<PThreadTimer<Type>
*>(obj)->Star
tRoutine)(static_cast<PThreadTimer<Type> *>(obj)->RoutineArgs);
[Deleted]
}
[Deleted]
};

template<> class PThreadTimer<void *(*)(void *)> :
public PThread<void *(*)(void *)>, public PThreadTimerBase {
private:
typedef void *(*FPType)(void *);

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

/*
* error: request for member `RoutineArgs' is ambiguous
* candidates are: void*PThreadBase::RoutineArgs
* void*PThreadBase::RoutineArgs
*/
static_cast<PThreadTimer<FPType> *>(obj)->StartRoutine(static_cast<PThreadTimer<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 1360

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

Similar topics

5
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...
4
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
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...
1
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...
4
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...
11
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...
5
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,...
7
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...
12
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
Oralloy
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,...
0
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...
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,...

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.