-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
31 lines (29 loc) · 748 Bytes
/
main.cc
File metadata and controls
31 lines (29 loc) · 748 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
#include <iostream>
#include <initializer_list>
using namespace std;
template<class T>
class object {
public:
object() { cout << "Default ctor!" << endl; }
object(T size, T default_value) { cout << "Parameterized ctor!" << endl; }
object(initializer_list<T> init) { cout << "Initializer list ctor!" << endl; }
void print() { cout << "print() is called!" << endl; }
};
int main() {
object<int> o1;
o1.print();
object<int> o2(10, 1);
o2.print();
object<int> o3{10, 1};
o3.print();
object<int> o4{};
o4.print();
object<int> o5();
// o5.print(); compile error
/**
* error: request for member ‘print’ in ‘o5’, which is of non-class type ‘object<int>()’
* o5.print();
* ^~~~~
*/
return 0;
}