By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

virtual inheritance problem with class template specializations

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.