Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic question on C++ templates

Tags:

c++

templates

arm

Consider this overly simple test:

class foo
{
    public:
        foo(int i);
        template< typename T > foo(T);
};

template<> foo::foo(int i) {}

Now, GCC is happy to accept this when compiling, but the RVCT compiler issues an error:

test.cpp", line 11: Error:  #792: "foo::foo(int)" is not an entity that can be explicitly specialized
 template<> foo::foo(int i) {}

Barring the issue of "why would you want to do this", is this legal C++ (from an academic point of view?)

Thanks in advance

like image 351
NullPointer Avatar asked Dec 11 '25 15:12

NullPointer


1 Answers

You are attempting to do an explicit specialization of template<typename T> foo(T) where T=int.

Did you actually want this?

template<typename T> foo::foo(T) {
}

--- EDIT ---

Just to make it clear: "explicit specialization" is legal in C++, but apparently your compiler does not support it (on individual methods anyway, maybe it does on whole classes?).

like image 116
Branko Dimitrijevic Avatar answered Dec 15 '25 04:12

Branko Dimitrijevic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!