rm 1.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td12/1.tar.gz tar xf 1.tar.gz make 1.1RENDU: 1.1.h
class Track : public SomeClass {
public:
Track() : SomeClass() {
cerr << "Default-Constructing @" << this << "\n";
}
Track(const SomeClass& obj) : SomeClass(obj) {
cerr << "Copy-Constructing @" << this << "\n";
}
~Track() {
cerr << "Destructing @" << this << "\n";
}
};
Testez votre code:
rm 2.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td12/2.tar.gz tar xf 2.tar.gz make 2.1RENDU: 2.1.h
const double x = 3.0;
SomeClass my_class;
Triplet<int, SomeClass, double> t(42, my_class, x);
cout << "Triplet: " << t.first << "; " << t.second << "; " << t.third << "\n";
t.third /= 2.0;
cout << t.third << "\n";
Cahier des charges:
rm 3.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td12/3.tar.gz tar xf 3.tar.gz make 3.1RENDU: 3.1.h
// Generic cardinality counter for hashable objects.
// It counts how many times a given object was inserted, all
// in constant time.
template<class T>
class CardinalityCounter {
public:
// Adds an object once, i.e. increments its cardinality count.
void Add(const T& t) {
// TODO
}
// Returns the current cardinality cound of object t, i.e. the number of
// times Add(t) was called. Can be 0 if t was never added.
int NumOccurences(const T& t) const {
// TODO
}
private:
// TODO
};
Testez votre code:
rm 4.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td12/4.tar.gz tar xf 4.tar.gz make 4.1RENDU: 4.1.h
std::map my_map;
my_map[5] = 4.567;
double* value_of_5 = &(my_map[5]);
int* key_of_5 = &(my_map.find(5)->first);
my_map[4] = 3;
my_map[2] = 8;
my_map.erase(4);
cout << *key_of_5; // Prints "5".
cout << *value_of_5; // Prints "4.567".
my_map[5] = 9.8;
cout << *key_of_5; // Prints "5".
cout << *value_of_5; // Prints "9.8".
Test: make 4.5