On Aug 2, 1:13 pm, ManicQin <Manic...@gmail.comwrote:
I've templated a simple class like the next:
template <class _T>
Just a nit, but don't use names starting with an underscore
followed by a capital letter. It's undefined behavior. For
that matter, don't use names starting with an underscore,
period.
class base
{
public:
base(_T newVal):m_data(newVal){}
private:
_T m_data;
};
AFAIK if the cTor receives _t byVal I can pass him numbers and
not just variable (feel free to correct me but that's the
behavior of VS9... and it sound reasonable)
What you mean is that if the parameter is passed by value, you
can use any arbitrary expression as the argument, provided it
has the right type (or can be implicitly converted to the right
type). That's right.
I want to add another cTor that receives the arg byRef but
than my compiler is having problems to deduce what cTor to
use..
Why?
how can I work around it?
It depends on why you want to do it. If nothing else, there's
always:
template< typename T >
class Base
{
public:
enum ByValue { byValue } ;
enum ByReference { byReference } ;
Base( ByValue, T value ) ...
Base( ByReference, T& value ) ...
} ;
I'd need a very, very strong reason before doing something like
that. (I think in close to twenty years experience with C++,
I've needed something like that exactly once.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34