- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextended.cpp
More file actions
Latest commit
37 lines (33 loc) · 695 Bytes
/
Copy pathextended.cpp
File metadata and controls
37 lines (33 loc) · 695 Bytes
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
/*
An example of how to add extended methods
to the main method of a class like so
a.mainMethod().extendedMethod()
https://ideone.com/Psh5Sj
*/
#include<iostream>
#include<string>
classExt
{
private:
classInt
{
private:
int i;
public:
Int(int i) : i(i) {}
operatorint() const { return i; }
intsquare() const { return i * i; }
std::string toString() const { return"\"" + std::to_string(i) + "\""; }
} _int;
public:
Ext(int val) : _int(val) {}
Int const &getInt() const { return _int; }
};
intmain()
{
Ext a{ 123 };
std::cout << a.getInt() << std::endl;
std::cout << a.getInt().square() << std::endl;
std::cout << a.getInt().toString() << std::endl;
return0;
}