Created
March 9, 2019 14:25
-
-
Save dskkato/814e5685b61474342d5e30c9dfe2853b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mystruct.h" | |
#include <iostream> | |
#include <string> | |
using mystruct::MyStruct; | |
using std::string; | |
int main() { | |
const string name("hoge"); | |
constexpr unsigned char age = 8; | |
MyStruct m(name, age); | |
std::cout << "Hello, " << m << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: all clean | |
all: a.out | |
./a.out | |
clean: | |
rm a.out | |
a.out: main.cpp mystruct.h mystruct.cpp | |
@echo "Compiling..." | |
$(CXX) -std=c++14 main.cpp mystruct.cpp -o a.out \ | |
-Wall -Wextra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mystruct.h" | |
namespace mystruct { | |
using std::ostream; | |
using std::string; | |
MyStruct::MyStruct(const string &name, const unsigned char age) | |
: name(name), age(age){}; | |
ostream &operator<<(ostream &os, const MyStruct &m) { | |
os << "(" << m.name << ", " << static_cast<unsigned int>(m.age) << ")"; | |
return os; | |
} | |
} // namespace mystruct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _MYSTRUCT_H_ | |
#define _MYSTRUCT_H_ | |
#include <iostream> | |
#include <string> | |
namespace mystruct { | |
class MyStruct { | |
public: | |
MyStruct() = delete; | |
MyStruct(const std::string &, const unsigned char); | |
friend std::ostream &operator<<(std::ostream &, const MyStruct &); | |
private: | |
const std::string name; | |
const unsigned char age; | |
}; | |
} // namespace mystruct | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment