Please point out the problems !!!!!!

This is a discussion on Please point out the problems !!!!!! within the C++ Programming forums, part of the General Programming Boards category; Dear all, I have got a difficult question to point out all the problems in the following C++ header code ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Please point out the problems !!!!!!

    Dear all,

    I have got a difficult question to point out all the problems in the following C++ header code segments. Could any C++ expert please 'enlight' me?

    Thanks a lot,
    miss muichu


    Code:
    /**\file	pets.hpp
    *	Classes to model members of household: the pet cat(s) and dog(s)
    *
    */
    
    // Forward declarations to avoid including <iostream.h>
    namespace std
    {
        template<class _E> struct char_traits;
        template<class _E, class _Tr> class basic_ostream;
        typedef basic_ostream<char, char_traits<char> > ostream;
    }
    
    using namespace std;
    
    class mouse;  // Mice are peats not pets!
    class location;
    class collar;
    
    /// Pet cat
    class cat
    {
    public:
    	void go_to(location& destination);
    
    	/// @return nul if fails
    	mouse* stalk();
    
    	/// Where are
    	location where() const;
    
    	/// @return true if the cat comes when called
    	virtual bool dinner_time();
    
    	/// put collar on
    	virtual set_collar(collar* new_collar);
    
    	/// Get the cat's collar
    	virtual collar* getCollar() const;
    
    	void purr (ostream& out);
    
    private:
    	// Data members ommitted
    };
    
    /// Pet cat
    class dog : public cat
    {
    public:
    	// inherits go_to() and where() from cat
    
    	/// @return nul if fails
    	mouse* stalk();
    	cat* chase_cat(cat* the_cat);
    
    	void purr(ostream& out) { throw "dog don't purr"; )
    	void bark(ostrea,& out);
    	void walkies();
    
    	/// put collar on
    	virtual set_collar(collar* new_collar);
    
    	virtual bool dinner_time() { return true; }
    
    private:
    	// Data members ommitted
    };

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Well, which ones have you found so far?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    2
    One point I can see is that there is no constructor and destructor in both cat and dog classes so that we should add them back. Moreover, the cat destructor should be made virtual as well.

    However, I believe that there are more problems in it. Can help?

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    38
    You should include <iosfwd> to get your forward i/o declarations.

    Code:
    void dog::bark(ostrea,& out); // typo
    Funny, how you derive dog from cat . A base animal class would be more natural imho.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    *sniff, sniff*

    mmmmmmmm, homework...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Looking at a Specified Point
    By gpr1me in forum Game Programming
    Replies: 1
    Last Post: 03-31-2006, 04:09 PM
  3. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  4. floating point problems
    By Bill83 in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2005, 02:57 PM
  5. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:14 PM

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