| 1 |
#include <new> |
| 2 |
#include <string> |
| 3 |
#include <vector> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#define DECLARE_DEFAULTERS(type, tname) \ |
| 8 |
class tname##_defaulter { \ |
| 9 |
public: \ |
| 10 |
tname##_defaulter(type a = 11, type b = 22, type c = 33); \ |
| 11 |
\ |
| 12 |
public: \ |
| 13 |
type m_a, m_b, m_c; \ |
| 14 |
}; \ |
| 15 |
type tname##_defaulter_func(int idx = 0, type a = 11, type b = 22, type c = 33); |
| 16 |
DECLARE_DEFAULTERS(short, short) |
| 17 |
DECLARE_DEFAULTERS(unsigned short, ushort) |
| 18 |
DECLARE_DEFAULTERS(int, int) |
| 19 |
DECLARE_DEFAULTERS(unsigned, uint) |
| 20 |
DECLARE_DEFAULTERS(long, long) |
| 21 |
DECLARE_DEFAULTERS(unsigned long, ulong) |
| 22 |
DECLARE_DEFAULTERS(long long, llong) |
| 23 |
DECLARE_DEFAULTERS(unsigned long long, ullong) |
| 24 |
DECLARE_DEFAULTERS(float, float) |
| 25 |
DECLARE_DEFAULTERS(double, double) |
| 26 |
|
| 27 |
std::string string_defaulter_func(int idx, const std::string& name1 = "aap", std::string name2 = "noot"); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class base_class { |
| 32 |
public: |
| 33 |
base_class() { m_b = 1; m_db = 1.1; } |
| 34 |
virtual ~base_class() {} |
| 35 |
virtual int get_value() { return m_b; } |
| 36 |
double get_base_value() { return m_db; } |
| 37 |
|
| 38 |
virtual base_class* cycle(base_class* b) { return b; } |
| 39 |
virtual base_class* clone() { return new base_class; } |
| 40 |
|
| 41 |
virtual void* mask(void* p) { return p; } |
| 42 |
|
| 43 |
public: |
| 44 |
int m_b; |
| 45 |
double m_db; |
| 46 |
}; |
| 47 |
|
| 48 |
class derived_class : public base_class { |
| 49 |
public: |
| 50 |
derived_class() { m_d = 2; m_dd = 2.2;} |
| 51 |
virtual int get_value() { return m_d; } |
| 52 |
double get_derived_value() { return m_dd; } |
| 53 |
virtual base_class* clone() { return new derived_class; } |
| 54 |
|
| 55 |
public: |
| 56 |
int m_d; |
| 57 |
double m_dd; |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
class a_class { |
| 63 |
public: |
| 64 |
a_class() { m_a = 1; m_da = 1.1; } |
| 65 |
virtual ~a_class() {} |
| 66 |
virtual int get_value() = 0; |
| 67 |
|
| 68 |
public: |
| 69 |
int m_a; |
| 70 |
double m_da; |
| 71 |
}; |
| 72 |
|
| 73 |
class b_class : public virtual a_class { |
| 74 |
public: |
| 75 |
b_class() { m_b = 2; m_db = 2.2;} |
| 76 |
virtual int get_value() { return m_b; } |
| 77 |
|
| 78 |
public: |
| 79 |
int m_b; |
| 80 |
double m_db; |
| 81 |
}; |
| 82 |
|
| 83 |
class c_class_1 : public virtual a_class, public virtual b_class { |
| 84 |
public: |
| 85 |
c_class_1() { m_c = 3; } |
| 86 |
virtual int get_value() { return m_c; } |
| 87 |
|
| 88 |
public: |
| 89 |
int m_c; |
| 90 |
}; |
| 91 |
|
| 92 |
class c_class_2 : public virtual b_class, public virtual a_class { |
| 93 |
public: |
| 94 |
c_class_2() { m_c = 3; } |
| 95 |
virtual int get_value() { return m_c; } |
| 96 |
|
| 97 |
public: |
| 98 |
int m_c; |
| 99 |
}; |
| 100 |
|
| 101 |
typedef c_class_2 c_class; |
| 102 |
|
| 103 |
class d_class : public virtual c_class, public virtual a_class { |
| 104 |
public: |
| 105 |
d_class() { m_d = 4; } |
| 106 |
virtual int get_value() { return m_d; } |
| 107 |
|
| 108 |
public: |
| 109 |
int m_d; |
| 110 |
}; |
| 111 |
|
| 112 |
a_class* create_c1(); |
| 113 |
a_class* create_c2(); |
| 114 |
|
| 115 |
int get_a(a_class& a); |
| 116 |
int get_b(b_class& b); |
| 117 |
int get_c(c_class& c); |
| 118 |
int get_d(d_class& d); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
namespace a_ns { |
| 123 |
extern int g_a; |
| 124 |
int get_g_a(); |
| 125 |
|
| 126 |
struct b_class { |
| 127 |
b_class() { m_b = -2; } |
| 128 |
int m_b; |
| 129 |
static int s_b; |
| 130 |
|
| 131 |
struct c_class { |
| 132 |
c_class() { m_c = -3; } |
| 133 |
int m_c; |
| 134 |
static int s_c; |
| 135 |
}; |
| 136 |
}; |
| 137 |
|
| 138 |
namespace d_ns { |
| 139 |
extern int g_d; |
| 140 |
int get_g_d(); |
| 141 |
|
| 142 |
struct e_class { |
| 143 |
e_class() { m_e = -5; } |
| 144 |
int m_e; |
| 145 |
static int s_e; |
| 146 |
|
| 147 |
struct f_class { |
| 148 |
f_class() { m_f = -6; } |
| 149 |
int m_f; |
| 150 |
static int s_f; |
| 151 |
}; |
| 152 |
}; |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
template<typename T> |
| 161 |
class T1 { |
| 162 |
public: |
| 163 |
T1(T t = T(1)) : m_t1(t) {} |
| 164 |
T get_value() { return m_t1; } |
| 165 |
|
| 166 |
public: |
| 167 |
T m_t1; |
| 168 |
}; |
| 169 |
|
| 170 |
template<typename T> |
| 171 |
class T2 { |
| 172 |
public: |
| 173 |
T2(T t = T(2)) : m_t2(t) {} |
| 174 |
T get_value() { return m_t2; } |
| 175 |
|
| 176 |
public: |
| 177 |
T m_t2; |
| 178 |
}; |
| 179 |
|
| 180 |
template<typename T, typename U> |
| 181 |
class T3 { |
| 182 |
public: |
| 183 |
T3(T t = T(3), U u = U(33)) : m_t3(t), m_u3(u) {} |
| 184 |
T get_value_t() { return m_t3; } |
| 185 |
U get_value_u() { return m_u3; } |
| 186 |
|
| 187 |
public: |
| 188 |
T m_t3; |
| 189 |
U m_u3; |
| 190 |
}; |
| 191 |
|
| 192 |
namespace a_ns { |
| 193 |
|
| 194 |
template<typename T> |
| 195 |
class T4 { |
| 196 |
public: |
| 197 |
T4(T t = T(4)) : m_t4(t) {} |
| 198 |
T get_value() { return m_t4; } |
| 199 |
|
| 200 |
public: |
| 201 |
T m_t4; |
| 202 |
}; |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
extern template class T1<int>; |
| 207 |
extern template class T2<T1<int> >; |
| 208 |
extern template class T3<int, double>; |
| 209 |
extern template class T3<T1<int>, T2<T1<int> > >; |
| 210 |
extern template class a_ns::T4<int>; |
| 211 |
extern template class a_ns::T4<a_ns::T4<T3<int, double> > >; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
void set_int_through_ref(int& i, int val); |
| 217 |
int pass_int_through_const_ref(const int& i); |
| 218 |
void set_long_through_ref(long& l, long val); |
| 219 |
long pass_long_through_const_ref(const long& l); |
| 220 |
void set_double_through_ref(double& d, double val); |
| 221 |
double pass_double_through_const_ref(const double& d); |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
class some_abstract_class { |
| 226 |
public: |
| 227 |
virtual ~some_abstract_class() {} |
| 228 |
virtual void a_virtual_method() = 0; |
| 229 |
}; |
| 230 |
|
| 231 |
class some_concrete_class : public some_abstract_class { |
| 232 |
public: |
| 233 |
virtual void a_virtual_method() {} |
| 234 |
}; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
class ref_tester { |
| 239 |
public: |
| 240 |
ref_tester() : m_i(-99) {} |
| 241 |
ref_tester(int i) : m_i(i) {} |
| 242 |
ref_tester(const ref_tester& s) : m_i(s.m_i) {} |
| 243 |
ref_tester& operator=(const ref_tester& s) { |
| 244 |
if (&s != this) m_i = s.m_i; |
| 245 |
return *this; |
| 246 |
} |
| 247 |
~ref_tester() {} |
| 248 |
|
| 249 |
public: |
| 250 |
int m_i; |
| 251 |
}; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
class some_convertible { |
| 256 |
public: |
| 257 |
some_convertible() : m_i(-99), m_d(-99.) {} |
| 258 |
|
| 259 |
operator int() { return m_i; } |
| 260 |
operator long() { return m_i; } |
| 261 |
operator double() { return m_d; } |
| 262 |
|
| 263 |
public: |
| 264 |
int m_i; |
| 265 |
double m_d; |
| 266 |
}; |
| 267 |
|
| 268 |
|
| 269 |
class some_comparable { |
| 270 |
}; |
| 271 |
|
| 272 |
bool operator==(const some_comparable& c1, const some_comparable& c2); |
| 273 |
bool operator!=(const some_comparable& c1, const some_comparable& c2); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
extern double my_global_double; |
| 278 |
extern double my_global_array[500]; |
| 279 |
extern double* my_global_ptr; |
| 280 |
static const char my_global_string1[] = "aap " " noot " " mies"; |
| 281 |
extern const char my_global_string2[]; |
| 282 |
|
| 283 |
class some_int_holder { |
| 284 |
public: |
| 285 |
some_int_holder(int val) : m_val(val) {} |
| 286 |
|
| 287 |
public: |
| 288 |
int m_val; |
| 289 |
char gap[7]; |
| 290 |
}; |
| 291 |
extern some_int_holder my_global_int_holders[5]; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
class some_class_with_data { |
| 296 |
public: |
| 297 |
class some_data { |
| 298 |
public: |
| 299 |
some_data() { ++s_num_data; } |
| 300 |
some_data(const some_data&) { ++s_num_data; } |
| 301 |
~some_data() { --s_num_data; } |
| 302 |
|
| 303 |
static int s_num_data; |
| 304 |
}; |
| 305 |
|
| 306 |
some_class_with_data gime_copy() { |
| 307 |
return *this; |
| 308 |
} |
| 309 |
|
| 310 |
const some_data& gime_data() { |
| 311 |
return m_data; |
| 312 |
} |
| 313 |
|
| 314 |
int m_padding; |
| 315 |
some_data m_data; |
| 316 |
}; |
| 317 |
|
| 318 |
class refers_to_self { |
| 319 |
public: |
| 320 |
refers_to_self* m_other = nullptr; |
| 321 |
}; |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
class pointer_pass { |
| 326 |
public: |
| 327 |
long gime_address_ptr(void* obj) { |
| 328 |
return (long)obj; |
| 329 |
} |
| 330 |
|
| 331 |
long gime_address_ptr_ptr(void** obj) { |
| 332 |
return (long)*((long**)obj); |
| 333 |
} |
| 334 |
|
| 335 |
long gime_address_ptr_ref(void*& obj) { |
| 336 |
return (long)obj; |
| 337 |
} |
| 338 |
|
| 339 |
static long set_address_ptr_ptr(void** obj) { |
| 340 |
(*(long**)obj) = (long*)0x4321; |
| 341 |
return 42; |
| 342 |
} |
| 343 |
|
| 344 |
static long set_address_ptr_ref(void*& obj) { |
| 345 |
obj = (void*)0x1234; |
| 346 |
return 21; |
| 347 |
} |
| 348 |
}; |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
class multi1 { |
| 353 |
public: |
| 354 |
multi1(int val) : m_int(val) {} |
| 355 |
virtual ~multi1(); |
| 356 |
int get_multi1_int() { return m_int; } |
| 357 |
|
| 358 |
private: |
| 359 |
int m_int; |
| 360 |
}; |
| 361 |
|
| 362 |
class multi2 { |
| 363 |
public: |
| 364 |
multi2(int val) : m_int(val) {} |
| 365 |
virtual ~multi2(); |
| 366 |
int get_multi2_int() { return m_int; } |
| 367 |
|
| 368 |
private: |
| 369 |
int m_int; |
| 370 |
}; |
| 371 |
|
| 372 |
class multi : public multi1, public multi2 { |
| 373 |
public: |
| 374 |
multi(int val1, int val2, int val3) : |
| 375 |
multi1(val1), multi2(val2), m_int(val3) {} |
| 376 |
virtual ~multi(); |
| 377 |
int get_my_own_int() { return m_int; } |
| 378 |
|
| 379 |
private: |
| 380 |
int m_int; |
| 381 |
}; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
class new_overloader { |
| 386 |
public: |
| 387 |
static int s_instances; |
| 388 |
|
| 389 |
public: |
| 390 |
void* operator new(std::size_t size); |
| 391 |
void* operator new(std::size_t, void* p) throw(); |
| 392 |
void operator delete(void* p, std::size_t size); |
| 393 |
}; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
template<class T> |
| 398 |
class my_templated_class { |
| 399 |
public: |
| 400 |
T m_b; |
| 401 |
}; |
| 402 |
|
| 403 |
template<class T> |
| 404 |
T my_templated_function(T t) { return t; } |
| 405 |
|
| 406 |
template class my_templated_class<std::vector<float> >; |
| 407 |
template char my_templated_function<char>(char); |
| 408 |
template double my_templated_function<double>(double); |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
class overload_one_way { |
| 413 |
public: |
| 414 |
int gime() const; |
| 415 |
std::string gime(); |
| 416 |
}; |
| 417 |
|
| 418 |
class overload_the_other_way { |
| 419 |
public: |
| 420 |
std::string gime(); |
| 421 |
int gime() const; |
| 422 |
}; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
class Thrower { |
| 427 |
public: |
| 428 |
void throw_anything(); |
| 429 |
void throw_exception(); |
| 430 |
}; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
class UsingBase { |
| 435 |
public: |
| 436 |
UsingBase(int n = 13) : m_int(n) {} |
| 437 |
virtual char vcheck() { return 'A'; } |
| 438 |
int m_int; |
| 439 |
}; |
| 440 |
|
| 441 |
class UsingDerived : public UsingBase { |
| 442 |
public: |
| 443 |
using UsingBase::UsingBase; |
| 444 |
virtual char vcheck() { return 'B'; } |
| 445 |
int m_int2 = 42; |
| 446 |
}; |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
class TypedefToPrivateClass { |
| 451 |
private: |
| 452 |
class PC { |
| 453 |
public: |
| 454 |
PC(int i) : m_val(i) {} |
| 455 |
int m_val; |
| 456 |
}; |
| 457 |
|
| 458 |
public: |
| 459 |
typedef PC PP; |
| 460 |
PP f() { return PC(42); } |
| 461 |
}; |