Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

A template question.

Thread view: 
Spark - 21 Feb 2007 18:40 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.