I have written the following source
#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;
}
and console print is 00000000 0. ( in visual studio 2010 )
if T is int*, T() == NULL? and is it always true?
This is called value-initialization, you are guaranteed 0
.
Plus, you don't need such a complicated example to demonstrate:
typedef int* T;
int main()
{
T x = T();
std::cout << x;
}
Yes. A value-initialized pointer is always null.
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