KaiserJohaan
KaiserJohaan

Reputation: 9240

Nested templates issue

I've got a nested template class declared like this:

template<typename T>
class IDMap
{
private:
    struct Item {
        uint16_t mVersion;
        T mItem;

        template <typename... Arguments>
        Item(uint16_t version, Arguments&&... args);
    };

    // ....
}

Later on I want to define the constructor of item, here is my attempt:

template <typename T, typename... Arguments>
IDMap<T>::Item::Item(uint16_t version, Arguments&&... args) : mVersion(version), mItem(std::forward<Arguments>(args)...)
{
}

The above dosn't compile though, it simply says 'IDMap<T>::Item::{ctor}' : unable to match function definition to an existing declaration. Something is missing - what is the correct syntax?

Upvotes: 4

Views: 66

Answers (1)

Anton Savin
Anton Savin

Reputation: 41301

The correct syntax is:

template <typename T>
template <typename... Arguments>
IDMap<T>::Item::Item(uint16_t version, Arguments&&... args) : mVersion(version), mItem(std::forward<Arguments>(args)...)
{
}

DEMO

Upvotes: 4

Related Questions