c++ const reference question Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

c++ const reference question

Post by orbitcowboy » Fri May 15, 2009 9:53 am

Hi friends,

maybe it is a stupid question, but what is the difference between the two parameters of Foo1 and Foo2? Or, does it the same?

Code: Select all


template <typename T> T Foo1(const T & val)
{
	//...
	return val;
}

template <typename T> T Foo2(T const & val)
{
	//...
	return val;
}
Both functions have (to my mind) a constant reference parameter, which can't be modified. But what does it mean to write the const before or after the 'T' ?

Best regards and many thanks

Orbitcowboy

Romas
I live to help wx-kind
I live to help wx-kind
Posts: 176
Joined: Mon Jun 16, 2008 11:07 am
Location: Kaunas

Post by Romas » Fri May 15, 2009 10:59 am

Hi,

const T& xx and T const& xx are the same. It is a matter of choise.

mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r » Fri May 15, 2009 3:36 pm

Romas wrote:Hi,

const T& xx and T const& xx are the same. It is a matter of choise.
Just to elaborate on Romas. There is no constant reference only references to constants as opposed to pointers where you can have a constant pointer or a pointer to a constant.

In the case of a reference as Romas says it is a matter of choice.

-Max

Post Reply