简体   繁体   中英

Template Parameter Initialization

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM