몇 년전에 웹에 공개된 글을 보고 정리했던 글이다.
더 읽기
더 읽기
class Base { public : virtual void f() { } } ; class Derived : public Base { private : void f() { } } ; int main() { Derived d ; d.f(); // 1. ? Base & ref =...
더 읽기
C++ 표준은 아니고 VC++ 7.0에서 생긴 키워드로 자식 클래스에서 부모 클래스의 멤버를 호출할 때 사용하면 편리하다. 이 키워드를 사용하면 부모 클래스의 이름이 바뀌어도 변경 없이 부모 클래스의 멤버를 호출할 수 있다. struct B1 { void mf(int) {} }; struct B2...
더 읽기
일반적인 함수의 기본 인자 값 void TEST_1(int nValue = 5 ) { std::cout << __FUNCTION__ << ". " << nValue << std::endl; } 위의 디폴트 값은 고정인데 아래처럼 동적으로 바꿀 수 있다. #include <iostream> #include <time.h> int GetNumber() { return...
더 읽기
보통 다른 클래스를 friend로 선언할 때 그 클래스 전체를 선언하는 경우가 많은데 클래스 전체가 아닌 일부 멤버 함수만을 friend로 선언할 수 있다. struct TEST2; struct TEST1 { void T1(); void T2(); }; struct TEST2 { friend void TEST1::T1(); private: int...
더 읽기
몇 년전에 웹에 공개된 글을 보고 번역했던 글이다.
더 읽기
몇 년전에 웹에 공개된 글을 보고 번역했던 글이다.
더 읽기
출처 #ifdef _DEBUG #define DEBUG_LOG(exp, ...) do {if (!(exp)){std::printf(__VA_ARGS__);}} while(0) #else #define DEBUG_LOG(exp, ...) do {(void)(exp);} while(0) #endif int main() { int x = 99; DEBUG_LOG(x > 100,"warning! x = %d", x); // x가 100 이하라면 경고를 표시 return 0;...
더 읽기
atoi #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> int main() { const std::string str("123"); auto num = std::atoi(str.c_str()); std::cout << typeid(num).name() << " : " << num << std::endl; } strtol #include <cstdlib> #include <iostream> #include <string> #include <typeinfo>...
더 읽기