Quick question to anyone experienced..

This is a discussion on Quick question to anyone experienced.. within the C++ Programming forums, part of the General Programming Boards category; Probably because of my newbishness but what's wrong with this? Thanks for helpin' Code: class mammal { public: mammal(int); }; ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    5

    Quick question to anyone experienced..

    Probably because of my newbishness but
    what's wrong with this? Thanks for helpin'
    Code:
    class mammal
    {
    public:
        mammal(int);
    };
    
    class dog : public mammal
    {
    public:
        dog();
    };
    
    mammal::mammal(int x)
    {}
    
    dog::dog()
    {}
    I tried it in codewarrior and points to the dog constructor saying "cannot construct class 'mammal'" and in dev-c++ it also points to dog constructor saying no matching function for call to `mammal::mammal()'
    Last edited by humbled; 07-08-2003 at 04:27 PM.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    You have no default constructor for mammal...so in your constructor for dog, you must construct mammal with an int. Like this for instance

    dog::dog():mammal(10)
    {}

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    5
    or I can just mammal(); in the mammal class right? Thanks for pointing it out

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Yeah, you could provide a default constructor for mammal. You could also change 'dog''s constructor to take an int and pass it to the mammal constructor (as Fordy showed).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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