If I have the following:
class T
{
public:
T(){}
};
void T()
{
}
int main()
{
T(); // this calls the function, how can I call the constructor T()?
}
I have no any issue with it, since I could be possible to rename it, but just curious how I could force it to call the constructor, and also I am asking to myself why the function call seems to have higher priority than the constructor. Additionally, why is there no warning message in regards of the duplicate name.
Besides what jaunchopanza said, you can qualify the call:
T::T();
With this version, you can create temporaries:
class T
{
public:
T(){}
};
void foo(T) {}
void T()
{
}
int main(){
foo(T::T());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With