Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Perhaps I being naive here, but I believe the following code should compile:

template <typename ... T>
struct Test {
        std::tuple<T> foo;
};

int main() {
        struct Test<int, long> test;

        return 0;
}

Instead g++ complains:

test.cpp:5: error: parameter packs not expanded with '...':
test.cpp:5: note:         'T'

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
267 views
Welcome To Ask or Share your Answers For Others

1 Answer

You do that by expanding the pack with ...:

template <typename... T>
struct Test
{
    std::tuple<T...> foo;
    //         ^^^^
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...