views:

47

answers:

1

Hi,

I wrote some C++ code in which I used Templates. Since I used templates, I could not initialize a couple of template class variables. I got an warning message from valgrind saying Conditional jump or move depends on uninitialized value(s). So is there a way to get around this and/or initialize template variables?? I couldn't think of a way to do it because even if I initailize them as NULL, when I use string data type a run time failure occurres.

Thank You!

+4  A: 

This is just a guess what you are asking about, so please ignore it if it's wrong.

IIUC, your problem is that, with template parameters, you cannot properly default-initialize built-ins and user-defined types. The way to solve this is:

T obj = T();

This works for both built-ins and UDTs.

sbi
thanks for your help sbi :)