summaryrefslogtreecommitdiff
path: root/I_anno
diff options
context:
space:
mode:
Diffstat (limited to 'I_anno')
-rw-r--r--I_anno/Programmazione_1/lab_14_12_18.cc41
1 files changed, 32 insertions, 9 deletions
diff --git a/I_anno/Programmazione_1/lab_14_12_18.cc b/I_anno/Programmazione_1/lab_14_12_18.cc
index 527da64..02bbd69 100644
--- a/I_anno/Programmazione_1/lab_14_12_18.cc
+++ b/I_anno/Programmazione_1/lab_14_12_18.cc
@@ -58,31 +58,54 @@ private:
};
template<typename T>
-class C : public A {
+class C;
+
+template<>
+class C<double> : public A {
public:
C(short n) : A{n} {
- if(typeid(T) == typeid(short)) {
- x = g(n);
- } else {
- x = static_cast<double>(log(1+n));
- }
+ x = static_cast<double>(log(1+n));
+ }
+
+ double foo(short r) const {
+ return g(r*x);
+ }
+
+ double g(double k) const {
+ return 3*k;
+ }
+
+ void print(ostream& os) {
+ os << "C<double> ";
+ getPtr(os);
+ os << ", x=" << x;
+ }
+private:
+ short x;
+};
+
+template<>
+class C<int> : public A {
+public:
+ C(short n) : A{n} {
+ x = g(n);
}
double foo(short r) const {
return g(r*x);
}
- T g(T k) const {
+ short g(short k) const {
return 3*k;
}
void print(ostream& os) {
- os << "C<" << typeid(T).name() << "> ";
+ os << "C<short> ";
getPtr(os);
os << ", x=" << x;
}
private:
- T x;
+ short x;
};
ostream& operator<<(ostream& os, A& a) {