-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathmyclass.h
More file actions
49 lines (39 loc) · 1.06 KB
/
myclass.h
File metadata and controls
49 lines (39 loc) · 1.06 KB
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
//The following ifndef/define/endif pattern is called a
//scope guard, and prevents the C++ compiler (actually, preprocessor)
//from including a header file more than once.
#ifndef __MY_CLASS_H_
#define __MY_CLASS_H_
#include <string>
#include <iostream>
class MyClass
{
int i_;
std::string name_;
public:
//Default constructor
MyClass() : i_(0) { }
MyClass(std::string name, int i)
: i_(i),
name_(name)
{ }
std::string const&
name() const { return name_; }
int
value() const { return i_; }
};
//
//Defining this method enables printing of MyClass objects
//using cout << m << endl; where m is a MyClass instance.
//
//It also allows printing using the print,println,printf, and
//printfln functions defined by ITensor.
//Use the "%s" token to print custom objects such as a MyClass
//object with printf and printfln.
//
inline std::ostream&
operator<<(std::ostream& s, MyClass const& m)
{
s << "MyClass(" << m.name() << "," << m.value() << ")";
return s;
}
#endif //__MY_CLASS_H