i know i've started aot of threads recently but i really want to learn c++. classes are killing me. my tutorial just isn't doing me anygood. its been great till now though look at it, ill put in comments where im having troubleCode:#include <iostream> using namespace std; class Dog { private: int age; int weight; public: Dog(); //Constructor?how and why does it work? ~Dog(); //Destructor?" " void setAge(int age);//whats with void? what is it, how does it //work? and o this is killing me, please just explain every line of code. i know its alot to ask but ill give you drugs for it(joking) int getAge(); void setWeight(int weight); int getWeight(); void speak(); }; Dog::Dog() { age = 0; weight = 0; cout << "Dog Constructor Called" << endl; } Dog::~Dog() { cout << "Dog Destructor Called" << endl; } void Dog::setAge(int age) { this->age = age; } int Dog::getAge() { return age; } void Dog::setWeight(int weight) { this->weight = weight; } int Dog::getWeight() { return weight; } void Dog::speak() { cout << "BARK!!" << endl; } int main() { Dog fido; Dog rover; cout << "Rover is " << rover.getAge() << " years old." << endl; cout << "He weighs " << rover.getWeight() << " lbs." << endl; cout << endl; cout << "Updating Rover's Age and Weight" << endl; rover.setAge(1); rover.setWeight(10); cout << "Rover is " << rover.getAge() << " years old." << endl; cout << "He weighs " << rover.getWeight() << " lbs." << endl; cout << endl; cout << "Fido is " << fido.getAge() << " years old." << endl; cout << "He weighs " << fido.getWeight() << " lbs." << endl; cout << "Setting Fido to be the same as Rover" << endl; fido = rover; cout << "Fido is " << fido.getAge() << " years old." << endl; cout << "He weighs " << fido.getWeight() << " lbs." << endl; rover.speak(); fido.speak(); cin.get(); return 0; }



LinkBack URL
About LinkBacks



why axon are always faster ?