tags:

views:

76

answers:

2

Hi guys, 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 ))
    { };
};
+4  A: 

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).

sepp2k
Thanks! Your answer counts too!
Alex Kremer
+7  A: 

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.

AProgrammer
You rock. Thanks!
Alex Kremer