Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- uint Base = 10;
- template <typename T>
- class SmartPointer {
- public:
- explicit SmartPointer(T* to_hold) : _p(to_hold) { std::cout << "Common sp ctor" << std::endl; }
- ~SmartPointer() { delete _p; }
- private:
- T* _p;
- };
- template <>
- class SmartPointer<int> {
- public:
- explicit SmartPointer(int* to_hold) : _p(to_hold) { std::cout << "Spec sp ctor" << std::endl; }
- ~SmartPointer() { std::cout << "ooo, int " << *_p << " is to be crashed."; delete _p; }
- private:
- int* _p;
- };
- int main1() {
- SmartPointer<double> pd(new double(3.5));
- SmartPointer<int> pi(new int(44));
- return 0;
- }
- template <int D>
- class BigInteger {
- public:
- BigInteger() = default;
- BigInteger(BigInteger<D - 1> low, uint up) : _low(low), _up(up) {}
- std::string ToString() const {
- std::string answer;
- answer.append(std::to_string(_up));
- answer.append(_low.ToString());
- return answer;
- }
- BigInteger<D> operator-() const {
- return {-_low, _up};
- }
- // template <int G>
- // BigInteger<D> operator+(const BigInteger<G>& right) const;
- private:
- BigInteger<D - 1> _low;
- uint _up = 0;
- };
- template <>
- class BigInteger<1> {
- public:
- BigInteger() = default;
- BigInteger(uint digit, bool is_positive) : _digit(digit), _is_positive(is_positive) {}
- std::string ToString() const { return std::to_string(_digit); }
- BigInteger<1> operator-() const {
- return {_digit, !_is_positive};
- }
- private:
- uint _digit = 0;
- bool _is_positive = true;
- };
- /*class BigIntegerWithSign {
- private:
- BigInteger<D> bi;
- bool sign;
- };
- */
- int main() {
- BigInteger<5> bi1;
- // BigInteger<5> bi2;
- // bi1 + bi2;
- BigInteger<5> bi2(-bi1);
- std::cout << bi2.ToString() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement