Thread: class Template problems

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I am trying to wrap my head around class templates.
    You should probably start with function templates and get comfortable with those first.

    Is my_dollar_account cappible of handiling multiple enteries like an array. If so, how does it take care of indexing?
    my_dollar_account is an object of a class you defined. So, when you ask whether it is capable of handling multiple entries like an array, it's all up to you. If you define objects of your class to have a member variable that is an array, then it can handle multiple entries. How does it take care of indexing? Anyway you decide.

    Instead, write an array class that holds ints. When you are done and it is working, replace int with T and make the class a template.
    I think that is the best approach as well. At this point, it's apparent you've chosen an example that is too difficult for you. Try creating a simpler templated class. For instance, declare a template that has one private member variable that you set in a constructor. Then add a simple get() function that returns the member variable. Your goal is to write a template that will handle any type.
    Last edited by 7stud; 02-16-2006 at 10:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. template function v.s. template class
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2007, 01:46 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM