Thread: function definition return type?

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    104

    function definition return type?

    In the following code (a function definition) CurrencyList is the name of a class. Is the first CurrencyList in the code a return type? If so, what does it mean for the return type to be of a class type? Does it mean an object of the class will be returned?
    Code:
    CurrencyList CurrencyList :: perfectChange(int amountToChange) const
    {
      int amt(size_);
      for (int i = 0; i<size_; i++)
         divMod(amountToChange, denom_[i].value, amt[i], amountToChange);
      return CurrencyList(amt);
    }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yes your understanding is correct.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    If so, what does it mean for the return type to be of a class type?

    The same thing it does as for a basic type like int. For instance, if your function returned an int, you would need to do something like this:

    int result=my_func();

    So, if the return type is CurrencyList, then you need to do something like this:

    CurrencyList myCL = my_func();

    Then you can use the variable myCL to access the member functions of the CurrencyList class. If the class contained a function showList() that displayed the data members, you could do this:

    myCL.showList();

    Does it mean an object of the class will be returned?

    Yep.

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. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM