Похожие чаты

Hi There, Why templated inline constructor cannot be called like

code below ?


template<typename T>
class CDerived : public CBase<T>
{
public:
CDerived() : CBase() {}// error

}

22 ответов

15 просмотров

You probably need to specify the type CBase<T>()

John- Автор вопроса
Pavel
You probably need to specify the type CBase<T>()

It is derived from CBase<T> and CBase<T>::CBase() is not templated.

John
It is derived from CBase<T> and CBase<T>::CBase() ...

Yes, but as far as I remember any time you refer to the base class, you need to specify the full type because CBase is still a templated class. Or you can make an alias inside your class using Base = CBase<T>; and use this Base as the type of the base class. https://ideone.com/BIpAjR

John- Автор вопроса
John
Do you know the article on standart ?

No, I don't know any good links about this unfortunately.

John
Do you know the article on standart ?

nevertheless @gameraccoon is right on this topic you have to _fully_ specify the class

Did you try CBase<T>::CBase() ?

John- Автор вопроса
Sunbro
nevertheless @gameraccoon is right on this topic ...

Why ? What is the purpose of ex: template<typename T> class CDerived : public CBase<T> { public: CDerived() : CBase<int>() {} }

John
Why ? What is the purpose of ex: template<typen...

The constructor would be CBase<T>, you are inheriting a templated class

John
Why ? What is the purpose of ex: template<typen...

Why the fuck did you put int in there oO

Kuntal M
The constructor would be CBase<T>, you are inherit...

typical example could be found in the boost libraries, where you inject certain behaviour into your class like this

Kuntal M
typical example could be found in the boost librar...

like obtaining a shared reference to itself

John- Автор вопроса
John
Why ? What is the purpose of ex: template<typen...

For example if you for some reason using multiple inheritance of many CBase specializations the compiler wouldn't be able to guess what you mean.

John- Автор вопроса
John- Автор вопроса
Pavel
For example if you for some reason using multiple ...

nah constructor doesnt like any other method.

John
can you show which ?

Check any TCP server implementation using boost::asio

John
nah constructor doesnt like any other method.

Not sure what you mean. You proposing a way of calling a constructor that wouldn't make sense in some situations.

John- Автор вопроса
Pavel
Not sure what you mean. You proposing a way of cal...

you mean supplying argument to template parameter wouldnt make sense ?

John
you mean supplying argument to template parameter ...

I gave you an example when the compiler wouldn't be able to decide what constructor you want to call in this case. I'm pretty sure it's not why it's not implemented, and even not sure if it's never going to be implemented this way in future (we already have CTAD, this is not so far from it).

John- Автор вопроса
Pavel
I gave you an example when the compiler wouldn't b...

Have you done it before ? the multiple inheritance of many CBase specialization ? The reason why we have to supply template argument to call base ctor ?

John
Have you done it before ? the multiple inheritanc...

Not sure, maybe, I've edited a lot of strange code including some weird template monsters. I agree that's not a common case, but these cases also need to be accounted.

Похожие вопросы

Обсуждают сегодня

Карта сайта