parameter values compiler error

This is a discussion on parameter values compiler error within the C++ Programming forums, part of the General Programming Boards category; Hello, i am hoping someone can help me with this code error. I am reading Sams Teach Yourself C++ in ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    parameter values compiler error

    Hello, i am hoping someone can help me with this code error. I am reading Sams Teach Yourself C++ in 21 days and i am using Dev C++ as the compiler. Right now i am stumped, I only have one error stopping me from compiling my program and running it. I have looked over the code in the book and have written it down exactly.
    The error is: ISO C++ forbids declaration of 'VolumeCube' with no type.
    And here is the code:
    Code:
    //demonstrates use of default parameter values
    #include <iostream>
    int VolumeCube(int length, int width = 25, int height = 1);
    
    int main()
    {
        int length = 100;
        int width = 50;
        int height = 2;
        int volume;
        
        volume = VolumeCube(length, width, height);
        std::cout << "First volume equals: " << volume << 
        "\n";
        
        volume = VolumeCube(length, width);
        std::cout << "Second time volume equals: " <<
        volume << "\n";
        
        volume = VolumeCube(length);
        std::cout << "Third time volume equals; " << volume << "\n";
        return 0;
    }
    
    VolumeCube (int length, int width, int height)
    {
                   
                   return (length * width * height);
                   }

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    VolumeCube needs a return type where you define it. You've got one where you prototyped it, but not at the definition.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    You left out the int return type in the definition of VolumeCube.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Did you REALLY write it down exactly as it is in the book? If "Sams Teach Yourself C++ in 21 days" defines functions without return type, I would recommend leaving this book.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    I'm sorry if this is a stupid question, but where would i define this, it doesn't really specify this. And yes i copied it exactly as it is in the book. I haven't had trouble with this book up until this point. Thank you very much for everyone's input.
    Last edited by novarage1; 11-04-2010 at 02:37 PM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Basically, change this:
    Code:
    VolumeCube (int length, int width, int height)
    {
    to:
    Code:
    int VolumeCube (int length, int width, int height)
    {
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Basically, change this:
    Code:
    VolumeCube (int length, int width, int height)
    {
    to:
    Code:
    int VolumeCube (int length, int width, int height)
    {
    Ah, I see. That was a stupid question. Just making sure i understand this, just a typo in this book i guess. Again, thanks for everyone's help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  2. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 04:01 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21