Thread: parameter values compiler error

  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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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
    28,413
    You left out the int return type in the definition of VolumeCube.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    733
    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 01:37 PM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Basically, change this:
    Code:
    VolumeCube (int length, int width, int height)
    {
    to:
    Code:
    int VolumeCube (int length, int width, int height)
    {
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 03:01 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM