On 2月22日, 上午6时21分, "Daniel Pitts" <googlegrou....@coloraura.com> wrote:
> On Feb 21, 10:40 am, "Spark" <liang.sp...@gmail.com> wrote:
>
>
>
> > 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.
>
> 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;
> }
>
> }
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
|