我寫了下面的源是一個int * NULL的默認值嗎?
#include <iostream>
using namespace std;
template <class T>
class AAA
{
public:
void f() { cout << T() << " "; }
};
int main (void)
{
AAA<int*> a;
AAA<int> b;
a.f(); /// in this case, T() == NULL??
b.f();
return 0;
}
和控制檯打印爲00000000 0(在Visual Studio 2010)
如果T爲int *,T()== NULL?它總是如此嗎?
是啊。總是。 http://stackoverflow.com/a/937257/707111 – Ryan 2012-08-04 17:33:14
可能的重複[什麼是C++指針的默認構造函數?](http://stackoverflow.com/questions/936999/what-is-the-default-constructor -for-c-pointer) – Troubadour 2012-08-04 17:48:01