dangerChihuahua007
dangerChihuahua007

Reputation: 20895

Why am I missing template arguments?

I created a template and gave it a default type:

template <typename T = unsigned>
class Network {
    // ...
}

However, when I try to instantiate a Network object

Network nw;

I get an error:

app.cpp:60:9: error: missing template arguments before 'nw'

Line 60 is Network nw;. Why am I missing template arguments if I specified that type T should default to unsigned when no type is explicitly mentioned?

Upvotes: 1

Views: 138

Answers (2)

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

It still needs to be:

Network<> nw;

even though it is default it still needs to be called like a template.

Upvotes: 8

Cornstalks
Cornstalks

Reputation: 38218

It's still a templated type, so it still needs the angle brackets:

Network<> nw;

Annoying? Yeah.

Upvotes: 8

Related Questions