int main(int argc, const char *argv[]) { Dog* dog = new YellowDog(); dog->bark(); delete dog; dog = new WhiteDog(); dog->bark(); delete dog; dog = new BlackDog(); dog->bark(); delete dog; return 0; }
int main() { Dog d = std::string("BArao") ; d.bark(); }
int main(void) { cout << "Test" << endl; Dog dog; dog.bark(); Cat cat; cat.sayMiew(); }
int main() { Dog fido; fido.setAge(3); fido.setWeight(15); fido.setColor("brown"); cout << "Fido is a " << fido.getColor() << " dog" << endl; cout << "Fido is " << fido.getAge() << " years old" << endl; cout << "Fido weight" << fido.getWeight() << " pounds" << endl; fido.bark(); return 0; }
int main() { using namespace std; cout << ~(-10) << endl; cout << (unsigned int)(-10) << endl; Dog dog; dog.eat = Dog_eat; dog.bark(); dog.eat(); return 0; }
void main () { //calling and instantiation of the classes Dog spots = Dog(); cout<<spots.weight << endl; spots.run(); spots.bark(); cout << spots.weight <<endl; system("PAUSE"); }
int main() { //classes represent real world objects. //a function in a class is a METHOD /ACTION //a variable in a class is a MEMBER / ATTRIBUTE //A class creates the *definition* of the data type (eg a dog) //The class is just the data type (like an int or a char) //You have to create an object of that type to interact with one //in the same way you declare variables. //classes are defined just like structs: //class <Name> //{ //}; //note the semi colon at the end. Class names usually begin with uppercase. //just like structs, you can create objects at the end: //class <Name> //{ //} obj1, obj2, obj3; Dog newDog; newDog.name = "Henry"; newDog.age = 2; cout << "Dog's name: " << newDog.name << endl; cout << "Dog's age: " << newDog.age << endl; newDog.bark(); system("pause"); return 0; }