简体   繁体   中英

C++: renaming templated class

I'm looking for some code to make it work

template <typename T, int a, int b> 
class first 
{   //not so important
};

main()
{
first<double,1,2> sth;
second<double> sth2;
}

Sth2 is the same type as sth, but has default parameters (for example) I do know I need some typedef. I tried

template <typename T>
struct help
{
typedef first<T,1,1> second;
};

but it works only with additional :: (help< double>::second) and i just want to change it for second< double>

Thank you for any ideas :)

You should just be able to define

template <typename T, int a=1, int b=2> class first

and then

first<double> sth2;

But if you really want two classes

template <typename T> class second : public first<T,1,1>

Should get you somewhere.

What about using default parameters? Otherwise igor might be right with C++11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM