I have a question about type parameters. Class Log is concrete one I
expected.
Log l;
l.setValue(10);
l.setValue("value");
l.setValue(10.0);
I tried to define this class as following. but got compile time error.
template<typename T>
class Log {
public:
void setValue(T s){
cout << s << endl;
}
};
Does anyone point me out?
Thanks in advance.
Ian Shef - 21 Feb 2007 19:08 GMT
"Spark" <liang.spark@gmail.com> wrote in news:1172083224.505757.295270
@p10g2000cwp.googlegroups.com:
> I have a question about type parameters. Class Log is concrete one I
> expected.
<snip>
> template<typename T>
> class Log {
[quoted text clipped - 5 lines]
>
> Does anyone point me out?
<snip>
You will get a much better response in a C++ newsgroup than in this one which
is for Java.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Daniel Pitts - 21 Feb 2007 22:21 GMT
> I have a question about type parameters. Class Log is concrete one I
> expected.
[quoted text clipped - 18 lines]
>
> Thanks in advance.
Even though you should have posted in the c++ newsgroup, I'll help
you..
You have defined a class Log, which is parameterized, what you wanted
to do was to create a function setValue which is parameterize.
class Log {
public:
template<typename T>
void setValue(T s) {
cout << s << endl;
}
}
Spark - 22 Feb 2007 08:47 GMT
> > I have a question about type parameters. Class Log is concrete one I
> > expected.
[quoted text clipped - 33 lines]
>
> }
I'm sorry,
I use google group. I really want to post to c++ newgroups. but
something wrong with my configuration, lead to wrong place.
anyway, thank you for Daniel's reply. It's helpful for me.
Spark