|
|
@ -4,45 +4,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Nail {
|
|
|
|
class Nail {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Nail(float length)
|
|
|
|
Nail(float length)
|
|
|
|
: length(length) {};
|
|
|
|
: length(length) {}
|
|
|
|
|
|
|
|
|
|
|
|
float getLength() {
|
|
|
|
float getLength() {
|
|
|
|
return length;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
float length;
|
|
|
|
float length;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tool {
|
|
|
|
class Tool {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual void use() {
|
|
|
|
virtual void use() {
|
|
|
|
std::cout << "Just using some tool." << std::endl;
|
|
|
|
std::cout << "Just using some tool." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hammer : public Tool {
|
|
|
|
class Hammer : public Tool {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual void use() {
|
|
|
|
virtual void use() {
|
|
|
|
std::cout << "Hammer time!" << std::endl;
|
|
|
|
std::cout << "Hammer time!" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void use(Nail nail) {
|
|
|
|
void use(Nail nail) {
|
|
|
|
std::cout << "The nail is " << nail.getLength() << " cm long"
|
|
|
|
std::cout << "The nail is " << nail.getLength() << " cm long"
|
|
|
|
<< std::endl;
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SledgeHammer : public Hammer {
|
|
|
|
class SledgeHammer : public Hammer {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void use(Nail nail __attribute__((unused))) {
|
|
|
|
void use(Nail nail __attribute__((unused))) {
|
|
|
|
throw std::runtime_error("Can't use a sledge hammer on nails!");
|
|
|
|
throw std::runtime_error("Can't use a sledge hammer on nails!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|