Thread: OOPs, I did it again.... lol....

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    It's so complex yet so simple at the same time, concepts are simple, syntax is so confusing though...

    I understand the whole thing except for the Constructors and Destructors, never really payed attention to those in school, i'll read over them then... Also, the parameters that operateDuck takes, I kindof don't understand them. I know that they take Ducks* and a myDuck.getSound() function.. but what do these data types mean?

    Code:
    void operateDuck(Duck* const pDuck, Sound* const pSound)
    I know that Duck* means we need a pointer to duck, but what is the const pDuck part? I know Sound* means we need a pointer to sound, but what does const pSound mean?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by Shamino
    It's so complex yet so simple at the same time, concepts are simple, syntax is so confusing though...

    I understand the whole thing except for the Constructors and Destructors, never really payed attention to those in school, i'll read over them then...
    Constructors are required to create objects of the class. Destructors are used to do some tidying up before an object is destroyed, which happens when an object goes out of scope. For instance, if you use 'new' in a constructor to dynamically allocate some memory for one of the member variables of an object, then you have to be sure to 'delete' it.

    [quote]Also, the parameters that operateDuck takes, I kindof don't understand them. I know that they take Ducks* and a myDuck.getSound() function.. but what do these data types mean?

    Code:
    void operateDuck(Duck* const pDuck, Sound* const pSound)


    I know that Duck* means we need a pointer to duck, but what is the const pDuck part? I know Sound* means we need a pointer to sound, but what does const pSound mean?
    I rewrote that function to make it easier to use, but to answer your question, making a function parameter const prohibits the function from changing the parameter. If you know that your function shouldn't change a parameter, then you should declare the parameter const. That way if you make a mistake and accidentally try to change the parameter inside the function, the compiler will flag it as an error and then you can correct the error. On the other hand, if you need to change the parameter inside the function, then don't declare the parameter const.

    The more times you look at the syntax and try to figure out what it does, the easier it becomes.
    Last edited by 7stud; 11-18-2005 at 12:35 AM.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Here is my attempt at an object oriented animal Hierarchy, I'm stuck from here, don't look at the content (what they say) it might be goofy and wrong!...

    My questions, How do I go about creating an operate Animal function, I'll end up throwing these into vectors and such, what would my next step from here be?

    Code:
    #include <iostream.h>
    
    class Animals
    {
    public:
    	Animals();
    	~Animals();
    
    	virtual void Movement()
    	{
    	}
    	virtual void Eat()
    	{
    	}
    };
    
    class Mammals : public Animals
    {
    public:
    	Mammals();
    	~Mammals();
    		void Movement()
    	{
    		cout << "I use my legs!" << endl;
    	}
    		void Eat()
    	{
    		cout << "I eat anything I can find!" << endl;
    	}
    };
    
    class Reptiles : public Animals
    {
    public:
    	Reptiles();
    	~Reptiles();
    		 void Movement()
    	{
    		cout << "I use my legs and slither!" << endl;
    	}
    		 void Eat()
    	{
    		cout << "I usually eat meat!" << endl;
    	}
    };
    
    class Birds : public Animals
    {
    public:
    	Birds();
    	~Birds();
    		void Movement()
    	{
    		cout << "I fly for the most part, some of the oddballs walk!" << endl;
    	}
    	    void Eat()
    	{
    		cout << "I usually eat meat!" << endl;
    	}
    
    };
    
    class Amphibians : public Animals
    {
    public:
    	Amphibians();
    	~Amphibians();
    		void Movement()
    	{
    		cout << "I generally crawl with my legs, and slither, AND swim!" << endl;
    	}
    		 void Eat()
    	{
    		cout << "I usually eat meat!" << endl;
    	}
    };
    
    class Fish : public Animals
    {
    public:
    	Fish();
    	~Fish();
    		void Movement()
    	{
    		cout << "You guessed it, I swim! (some of us get beached though, stupid fat whales!)" << endl;
    	}
    		 void Eat()
    	{
    		cout << "I eat anything I can find in the water!" << endl;
    	}
    };
    
    int main()
    {
    	return 0;
    }
    Last edited by Shamino; 11-18-2005 at 01:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why C++ is not OOPS
    By noobcpp in forum C++ Programming
    Replies: 13
    Last Post: 10-20-2008, 01:20 PM
  2. lol need some help :D
    By lolol in forum C Programming
    Replies: 28
    Last Post: 03-28-2008, 07:46 AM
  3. Oops, she did it again...
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-19-2004, 02:34 PM
  4. lol, funniest acting program EVER -- and i need help with it :(
    By Leeman_s in forum Windows Programming
    Replies: 1
    Last Post: 01-09-2003, 07:27 PM
  5. Lol!
    By no-one in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 02-11-2002, 12:29 PM