From 17ed8ba675689a2a1b377f4c7fdc7b42cada28d1 Mon Sep 17 00:00:00 2001 From: unlockable Date: Thu, 18 May 2023 19:48:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=92=E5=BD=92Factorial.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OOP/test.cpp | 66 +++++++--------------------------------------------- 1 file changed, 8 insertions(+), 58 deletions(-) diff --git a/OOP/test.cpp b/OOP/test.cpp index d3a898f..7227b7f 100644 --- a/OOP/test.cpp +++ b/OOP/test.cpp @@ -3,68 +3,18 @@ using std::cout; using std::cin; using std::endl; -class A { -protected: - int a; - -public: - A(int _a) : a(_a) { - } - void display() { - std::cout << a << std::endl; - } +template +struct Factorial { + static const unsigned long long value = x * Factorial::value; }; -class B : virtual public A { -protected: - int b; - -public: - B(int _a, int _b) : A(_a+1), b(_b) { - } - void display() { - A::display(); - std::cout << b << std::endl; - } +template <> +struct Factorial<0> { + static const unsigned long long value = 1; }; -class C : virtual public A { -protected: - int c; - -public: - C(int _a, int _c) : A(_a + 2), c(_c) { - } - void display() { - A::display(); - std::cout << c << std::endl; - } -}; - -// class D : public B, public C { -// protected: -// int d; - -// public: -// D(int _a, int _b, int _c, int _d) :A(_a), B(_a, _b), C(_a, _c), d(_d){}; - -// void display() { -// A::display(); -// B::display(); -// C::display(); -// std::cout << d << std::endl; -// } -// }; - int main() { - // D objD(1, 2, 3, 4); - // objD.display(); - // cout << "---\n" << sizeof(A) << endl << sizeof(B) << endl << sizeof(C) << endl; - // cout << -13 % 6 << endl; - cout << "---"; - endl(cout); - endl(cout); - cout << "---"; - endl(cout); + Factorial<20> a; + cout << a.value << endl; return 0; } \ No newline at end of file