re-indent
This commit is contained in:
parent
d08cb5c79c
commit
7579fe1f6e
3 changed files with 35 additions and 35 deletions
12
casts.cpp
12
casts.cpp
|
@ -2,12 +2,12 @@
|
|||
#include <string>
|
||||
|
||||
class mybase {
|
||||
protected:
|
||||
std::string ids;
|
||||
protected:
|
||||
std::string ids;
|
||||
|
||||
public:
|
||||
mybase(std::string ids)
|
||||
: ids(ids) {}
|
||||
public:
|
||||
mybase(std::string ids)
|
||||
: ids(ids) {}
|
||||
|
||||
virtual void foo() {
|
||||
std::cout << "i'm a mybase! ids: " << ids << std::endl;
|
||||
|
@ -15,7 +15,7 @@ class mybase {
|
|||
};
|
||||
|
||||
class myclass : public mybase {
|
||||
public:
|
||||
public:
|
||||
myclass(std::string ids)
|
||||
: mybase(ids) {}
|
||||
|
||||
|
|
48
classes.cpp
48
classes.cpp
|
@ -2,39 +2,39 @@
|
|||
#include <vector>
|
||||
|
||||
class Animal {
|
||||
public:
|
||||
Animal() {
|
||||
std::cout << "constructor" << std::endl;
|
||||
}
|
||||
Animal(const Animal& other) {
|
||||
std::cout << "copy constructor (" << &other << ")" << std::endl;
|
||||
}
|
||||
public:
|
||||
Animal() {
|
||||
std::cout << "constructor" << std::endl;
|
||||
}
|
||||
Animal(const Animal& other) {
|
||||
std::cout << "copy constructor (" << &other << ")" << std::endl;
|
||||
}
|
||||
|
||||
// Note: using *virtual* does the difference here!
|
||||
virtual void makeSound() const {
|
||||
std::cout << "<generic animal sound> from " << this << std::endl;
|
||||
}
|
||||
// Note: using *virtual* does the difference here!
|
||||
virtual void makeSound() const {
|
||||
std::cout << "<generic animal sound> from " << this << std::endl;
|
||||
}
|
||||
|
||||
Animal& operator= (Animal &a) {
|
||||
std::cout << "lol, operator= of " << this;
|
||||
std::cout << "(arg: " << &a << ")" << std::endl;
|
||||
Animal& operator= (Animal &a) {
|
||||
std::cout << "lol, operator= of " << this;
|
||||
std::cout << "(arg: " << &a << ")" << std::endl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class Cow : public Animal {
|
||||
public:
|
||||
void makeSound() const {
|
||||
std::cout << "Mooh. from " << this << std::endl;
|
||||
}
|
||||
public:
|
||||
void makeSound() const {
|
||||
std::cout << "Mooh. from " << this << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Cat : public Animal {
|
||||
public:
|
||||
void makeSound() const {
|
||||
std::cout << "Meow? from " << this << std::endl;
|
||||
}
|
||||
public:
|
||||
void makeSound() const {
|
||||
std::cout << "Meow? from " << this << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
void call(Animal a) {
|
||||
|
|
10
poly.cpp
10
poly.cpp
|
@ -3,11 +3,11 @@
|
|||
|
||||
/* abstract */
|
||||
class Animal {
|
||||
public:
|
||||
// virtual std::string talk() = 0; /* pure virtual */
|
||||
virtual std::string talk() { /* or an implementation */
|
||||
return "<sound>";
|
||||
}
|
||||
public:
|
||||
// virtual std::string talk() = 0; /* pure virtual */
|
||||
virtual std::string talk() { /* or an implementation */
|
||||
return "<sound>";
|
||||
}
|
||||
};
|
||||
|
||||
class Cat : public Animal {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue