Primitive initialization with templates

Function change() can change local variable tmp or can fail to change it.
1
2
3
4
5
6
7
8
9
void change_tmp(void *buffer);

template<class T>
T getInfo()
{
	T tmp;   // <----- I want here a default initialization. 0 for numbers, "" for strings.
	change_tmp(&tmp);  // Can fail to change tmp.
	return tmp;
}

How can I do this default initialization on primitives?
For instance if T=int I have
int tmp;
but I want
int tmp=0;
How about
T tmp = T(); // Default value for T
?
Last edited on
if you have a fairly uptodate with c++11 compiler then:

T tmp {T()}

or if you are still on 'old compiler'
then
T tmp = T();


EDIT
I have to edit to say that I'm not keen on your change_tmp function.
Where exactly are you going with that?
Last edited on
Thank you very much guys.

Code is simplified.
change_tmp in reality is the OpenCL clDeviceInfo().
http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clGetDeviceInfo.html
Topic archived. No new replies allowed.