Pergunta

So I've got template class (abbreviated) like:

template <typename keyT, typename valueT>
class hashMap {
public:
    using dataT = pair<keyT,valueT>;
    using maybeT = optional<dataT>;
    maybeT notFound = optional<dataT> ();
    maybeT find(keyT &v);
    <snip>
};

When I try to define find(), I have

template <typename keyT, typename valueT>
hashMap::maybeT hashMap<keyT,valueT>::find(keyT &k)
{

and hashMap::maybeT isn't recognized ("expected a class or namespace"). Qualifying hashMap with keyT and valueT doesn't help, either.

How can I export these aliases (or typedefs, if there is a way to make that work).

Foi útil?

Solução

You need to disambiguate the dependent name:

template <typename keyT, typename valueT>
typename hashMap<keyT, valueT>::maybeT hashMap<keyT,valueT>::find(keyT &k)
// ^^^^^
{
    // ...
}

(Since you're writing a template, you might as well keep everything inline, though, and cut down on the code noise. Otherwise you should add inline to the member function declaration.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top