10

I have the following class definition:

class image {

public:

  template <class T> image(int w, int h);
  virtual ~image();

  void clear();
};

template <class T> image::image(int w, int h) {
  ...
  ...
}

The constructor is defined in the same header file. Now, how do I instantiate an object of this class?

I tried this

image a<float>(128, 128);

but got the following error

error: expected initializer before '<' token
image a<float>(128, 128);

How do I do this?

manatttta
  • 3,054
  • 4
  • 34
  • 72
  • 5
    Unrelated to your problem, but don't use leading double underscore in your own symbols, [they are reserved in all scopes](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – Some programmer dude Nov 12 '15 at 10:21
  • 1
    Yes but both cases in the duplicates the answer is no but in this case it is invokable if you tweak the parameters to use __T so it can be deduced. – Shafik Yaghmour Nov 12 '15 at 10:26
  • 1
    Your methods are not `public`. – dkg Nov 12 '15 at 10:27
  • So, the only way is to tweak an argument into the ctor of type `T`? – manatttta Nov 12 '15 at 10:53

0 Answers0