class Test
{
public:
Test(){
cout<<"Inside ctor"<<endl;
}
~Test()
{
cout<<"Inside dtor"<<endl;
}
};
int main() {
Test t; //works fine
t.~Test(); //works fine
Test(); //works fine
t.Test::Test(); //gives error... Why??
return 0;
}
**`Error`**
Building file: ../src/testCtor.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testCtor.d" -MT"src/testCtor.o" -o "src/testCtor.o" "../src/testCtor.cpp"
../src/testCtor.cpp: In function ‘int main()’:
../src/testCtor.cpp:37:10: error: cannot call constructor ‘Test::Test’ directly
t.Test::Test(); //error
^~~~
我尝试搜索解决方案,但是找不到任何具体的东西。有人可以帮我解释为什么这样做是错误的吗?
预先感谢.. !!