In class Foo, I have a member variable of type Bar. Bar is constructed in my Foo constructor by passing in a pointer to an array like this:
template<typename> T
class Foo{
Bar myBar;
size_t mySize;
size_t top;
Foo(size):myBar(new T[size]),mySize(size),top(0){}; //creates a Bar element of certain size
}
template<typename> T
class Bar{
T* myListPtr;
Bar::Bar(T* tPtr):myListPtr(tPtr){} //stores a pointer to a T array
}
Now to my knowledge, if T has a default constructor, C++ should be calling this on all elements in the array. However when I output the values that are being pointed to, I got an array like this(with size=8 and T type 'double')
9.3218e-306
0
0
0
0
3.81522e-270
nan
nan
How do I make sure that all the values are default initialized and not just some. This array might hold char, double, any type, but the type will always have have a default constructor. What could be causing this problem?