Hello all ... I am trying to learn C++ ... again (PHP is so much easier).
Here is my question:
Should I use the arrow operator to access class methods and the dot operator to access class members?
Here is the code I am using:
Code:#ifndef CREATURE class Creature { public: Creature(){ std::cout << "Creating Creature" << std::endl; } ~Creature(){ std::cout << "Destroying Creature" << std::endl; } void eat(){ std::cout << "Creature is eating" << std::endl; } void setBloodType(char* bType){ bloodType = bType; } char* getBloodType(){ return bloodType; } protected: char* bloodType; }; #define CREATURE 1 #endifCode:#ifndef MAMMAL class Mammal : public Creature { public: Mammal(){ std::cout << "Creating Mammal" << std::endl; } ~Mammal(){ std::cout << "Destroying Mammal" << std::endl; } void eat(){ std::cout << "Mammal is eating" << std::endl; } }; #define MAMMAL 1 #endifTIA!Code:#include<iostream> #include "Creature.cpp" #include "Mammal.cpp" using namespace std; int main(){ Creature *creature = new Creature; char* CreatureBloodType = "Unknown"; creature->setBloodType(CreatureBloodType); creature->eat(); cout << "Creature blood type is " << creature->getBloodType() << endl; delete creature; char* MammalBloodType = "O Negative"; Mammal *mammal = new Mammal; mammal->eat(); mammal->setBloodType(MammalBloodType); cout << "Mammal blood type is " << mammal->getBloodType() << endl; delete mammal; system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks




)
I used to be an adventurer like you... then I took an arrow to the knee.