File features.hΒΆ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <cmath>
#include <iostream>
#include <vector>


//-----
unsigned int gUint = 0;

//-----
class Abstract {
public:
    virtual ~Abstract() {}
    virtual void abstract_method() = 0;
    virtual void concrete_method() = 0;
};

void Abstract::concrete_method() {
    std::cout << "called Abstract::concrete_method" << std::endl;
}

//-----
class Concrete : Abstract {
public:
    Concrete(int n=42) : m_int(n), m_const_int(17) {}
    ~Concrete() {}

    virtual void abstract_method() {
        std::cout << "called Concrete::abstract_method" << std::endl;
    }

    virtual void concrete_method() {
        std::cout << "called Concrete::concrete_method" << std::endl;
    }

    void array_method(int* ad, int size) {
        for (int i=0; i < size; ++i)
            std::cout << ad[i] << ' ';
        std::cout << '\n';
    }

    void array_method(double* ad, int size) {
        for (int i=0; i < size; ++i)
            std::cout << ad[i] << ' ';
        std::cout << '\n';
    }

    void uint_ref_assign(unsigned int& target, unsigned int value) {
        target = value;
    }

    Abstract* show_autocast() {
        return this;
    }

    operator const char*() {
        return "Hello operator const char*!";
    }

public:
    double m_data[4];
    int m_int;
    const int m_const_int;

    static int s_int;
};

typedef Concrete Concrete_t;

int Concrete::s_int = 321;

void call_abstract_method(Abstract* a) {
    a->abstract_method();
}

//-----
class Abstract1 {
public:
    virtual ~Abstract1() {}
    virtual std::string abstract_method1() = 0;
};

class Abstract2 {
public:
    virtual ~Abstract2() {}
    virtual std::string abstract_method2() = 0;
};

std::string call_abstract_method1(Abstract1* a) {
    return a->abstract_method1();
}

std::string call_abstract_method2(Abstract2* a) {
    return a->abstract_method2();
}

//-----
int global_function(int) {
    return 42;
}

double global_function(double) {
    return std::exp(1);
}

int call_int_int(int (*f)(int, int), int i1, int i2) {
    return f(i1, i2);
}

template<class A, class B, class C = A>
C multiply(A a, B b) {
    return C{a*b};
}

//-----
namespace Namespace {

    class Concrete {
    public:
        class NestedClass {
        public:
            std::vector<int> m_v;
        };

    };

    int global_function(int i) {
        return 2*::global_function(i);
    }

    double global_function(double d) {
        return 2*::global_function(d);
    }

} // namespace Namespace

//-----
enum EFruit {kApple=78, kBanana=29, kCitrus=34};
enum class NamedClassEnum { E1 = 42 };

//-----
void throw_an_error(int i);

class SomeError : public std::exception {
public:
    explicit SomeError(const std::string& msg) : fMsg(msg) {}
    const char* what() const throw() override { return fMsg.c_str(); }

private:
    std::string fMsg;
};

class SomeOtherError : public SomeError {
public:
    explicit SomeOtherError(const std::string& msg) : SomeError(msg) {}
    SomeOtherError(const SomeOtherError& s) : SomeError(s) {}
};