Alex Kremer
Alex Kremer

Reputation: 13

C++ / templates / GCC 4.0 bug?

Provided the code below:

template<class _ResClass, class _ResLoader=DefaultLoader>
class Resource 
: public BaseResource
{
private:
    _ResClass data_;

public:
    explicit Resource(const std::string& path)
    : data_( _ResLoader::load< _ResClass >( path ))
    { };
};

Why would it fail but this one will work?:

template<class _ResClass, class _ResLoader=DefaultLoader>
class Resource 
: public BaseResource
{
private:
    _ResClass data_;

public:
    explicit Resource(const std::string& path)
    : data_( **DefaultLoader**::load< _ResClass >( path ))
    { };
};

Upvotes: 1

Views: 152

Answers (2)

AProgrammer
AProgrammer

Reputation: 52274

load is a dependant name, so

data_( _ResLoader::template load< _ResClass >( path ))

for the same reason as typename is needed when a dependant name is a type.

Upvotes: 7

sepp2k
sepp2k

Reputation: 370092

You need to do _ResLoader::template load< _ResClass >( path ) instead of _ResLoader::load< _ResClass >( path ).

When accessing a template nested withing a template parameter, you need to use the template keyword (same way you need to use typename keyword for types nested in template parameters).

Upvotes: 4

Related Questions