Yes, this is expected. There is no general way to say "I meant the class, not the function, with this name" because you are not supposed to re-use names.
typename
cannot help you here, though since Foo
is a class and C++ provides backward compatibility with C's struct T
type syntax, you can say class Foo
or struct Foo
instead:
int main() {
// Calls function
Foo(42);
// Constructs a `[class] Foo`
class Foo foo(42);
}
This is something of a hack, though, and doesn't really solve the fundamental problem which is that the symbols in your program are not clearly differentiated from one another.
Depending on your real circumstances, a namespace might solve your problem in a robust and clear way. Libraries should be using them (but often don't).
Otherwise simply improve your names... and I don't mean by calling one Foo
and the other FooClass
!