본문 바로가기

::public/C++63

연산자 오버로딩 #include using namespace std; class Vector{public: float x; float y; float z; // 단항 연산자 +, +vector = vector Vector operator+() const { return Vector{ +x, +y, +z }; } // 단항 연산자 -, -vector = vector Vector operator-() const { return Vector{ -x, -y, -z }; } // 이항 연산자 +, vector + vector = vector Vector operator+(const Vector& v) const { return Vector{ x + v.x, y + v.y, z + v.z }; } // 이항 연산자 -, vecto.. 2020. 9. 15.
extern *다른 파일에서 선언한 전역변수를 호출하여 사용할 수 있다. 프로세스의 정적 영역 어딘가에 위치하고 프로그램 시작부터 끝까지 어딘가에 존재한다. // source.cpp int num = 100; // main.cpp extern int num; int main() { cout 2020. 9. 1.
공용체(union) #include using namespace std; int main(){ { // 공용체를 사용하지 않는 경우. // idInteger, idChars 의 메모리 낭비 struct Product { int idType; int idInteger; char idChars[10]; }; Product product = { 0, 12 }; if (product.idType == 0) cout 2020. 7. 13.
구조체(struct) #include #include using namespace std; int main(){ struct Person { float height; float weight; char name[10]; short grade; }; { Person person; person.height = 174.2f; person.weight = 67.8f; person.grade = 1; strcpy_s(person.name, 10, "David"); cout 2020. 7. 13.
string #include #include using namespace std; int main() { { string str = "abcd"; cout 2020. 7. 13.
문자열 #pragma warning(disable: 4996)#include #include using namespace std; int main(){ { char str[] = "abc"; cout 2020. 7. 13.