OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Templated class with constructor arguments [duplicate]

  • Thread starter Thread starter KiraHoneybee
  • Start date Start date
K

KiraHoneybee

Guest
Consider this class:

Code:
template <typename t>
class Something
{
public:
    Something(t theValue) {mValue=theValue;}
    t mValue;
};

When I do this, everything is okay:

Code:
Something<float>* mSomething=new Something<float>(100);

HOWEVER, if I try to do this:

Code:
Something<float> mSomething(100);

I am declaring the above inside another class-- i.e.

Code:
class SomethingElse
{
public:
     Something<float> mSomething(100);
};

It tells me that anything I put inside the parenthesis is a syntax error.

What exactly is the necessary syntax here-- or is this some quirk of templates and thus not possible?

Fail code example here: https://wandbox.org/permlink/anaQz9uoWwV9HCW2
Continue reading...
 

Latest posts

Top