Answer the question
In order to leave comments, you need to log in
How can I change the code to make the example work?
Hi all. I have two classes
class Audioformat {
public:
string titel() { return ""; }
string info() { return ""; }
};
int mp3_counter = 0;
class MP3_Format : public Audioformat {
public:
string titel() { return song; }
string info() { return "MP3"; }
private:
string song;
};
bool test_A1_a() {
#ifdef A1_a
Audioformat * af = new MP3_Format("Hey Joe");
string info = af->info();
string absp = af->titel();
return (info == "MP3" && absp == "Hey Joe");
#else
return false;
#endif
}
Answer the question
In order to leave comments, you need to log in
1. The title is a title, not a titel
2. Each new must be followed by a delete. It's better to wrap Audioformat* in std::unique_ptr which does the delete itself:
#include <memory>
std::unique_ptr<Audioformat> af(new Audioformat(""));
af->info(); af->title();
// Не нужен delete :D
class Audioformat {
public:
virtual string info() = 0;
};
class MP3_Format : public Audioformat {
public:
string info() override { return "MP3"; }
};
class Audioformat {
public:
virtual ~Audioformat() {}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question