P
Phil Endecott
Dear Experts,
It seems that I'm not allowed to use a locally-declared type as an
implicit template parameter. Example:
struct Foo {
template <typename T>
Foo(const T& t) {}
};
void f() {
struct {
int a;
} s;
Foo x(s); // doesn't work; "no matching function"
}
void g() {
struct S {
int a;
};
S s;
Foo x(s); // also doesn't work, so it's the local scope not
// being anonymous that's the problem
}
struct stru {
int a;
};
void h() {
stru s;
Foo x(s); // does work.
}
This surprises me. Is this right? What's the rationale?
Cheers, Phil.
It seems that I'm not allowed to use a locally-declared type as an
implicit template parameter. Example:
struct Foo {
template <typename T>
Foo(const T& t) {}
};
void f() {
struct {
int a;
} s;
Foo x(s); // doesn't work; "no matching function"
}
void g() {
struct S {
int a;
};
S s;
Foo x(s); // also doesn't work, so it's the local scope not
// being anonymous that's the problem
}
struct stru {
int a;
};
void h() {
stru s;
Foo x(s); // does work.
}
This surprises me. Is this right? What's the rationale?
Cheers, Phil.