virtual inheritance problem with class template specializations

  • Thread starter Tseng, Ling-hua
  • Start date
T

Tseng, Ling-hua

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]
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top