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