원문 : http://blogs.msdn.com/vcblog/Default.aspx?p=2
이전 포스트(rvalue references: initialization) 함수가 어떻게 lvalue파라메터와 const lvalue 참조 타입의 파라메터가 오버로드 되는지 알았습니다
C++0x 에서는 rvalue 참조와 const rvalue 참조 피라메터를 가지는 함수를 오버로드 할 수 있습니다. 아래예제는 하나의 인자를 갖는 함수를 오버로드한 예제입니다. :
C:\Temp>type four_overloads.cpp
|
#include <iostream> #include <string> using namespace std; void meow(string& s) { cout << "meow(string&): " << s << endl; } void meow(const string& s) { cout << "meow(const string&): " << s << endl; } void meow(string&& s) { cout << "meow(string&&): " << s << endl; } void meow(const string&& s) { cout << "meow(const string&&): " << s << endl; } string strange() { return "strange()"; } const string charm() { return "charm()"; } int main() { string up("up"); const string down("down"); meow(up); meow(down); meow(strange()); meow(charm()); return 0; } |
결과 :
|
C:\Temp>cl /EHsc /nologo /W4 four_overloads.cpp four_overloads.cpp C:\Temp>four_overloads meow(string&): up meow(const string&): down meow(string&&): strange() meow(const string&&): charm() |
예제에서 Type& , const Type& , Type&& , const Type&& 에 따라 오버로드한 방법은 꽤 유용한 방법은 아닙니다. 아래 예제와 같이 const Type& 와Type&&를 인자로 가지는 함수만 오버로드 하는 방법이 더 간편 합니다. :
C:\Temp>type two_overloads.cpp
|
#include <iostream> #include <ostream> #include <string> using namespace std; void purr(const string& s) { cout << "purr(const string&): " << s << endl; } void purr(string&& s) { cout << "purr(string&&): " << s << endl; } string strange() { return "strange()"; } const string charm() { return "charm()"; } int main() { string up("up"); const string down("down"); purr(up); purr(down); purr(strange()); purr(charm()); } |
|
C:\Temp>cl /EHsc /nologo /W4 two_overloads.cpp two_overloads.cpp C:\Temp>two_overloads purr(const string&): up purr(const string&): down purr(string&&): strange() purr(const string&): charm() |
위의 예제는 아래의 규칙을 따라서 함수 호출이 이루어 집니다.:
· 초기화 규칙은 거부될 수 있습니다.
· Lvalue는 Lvalue참조에 우선적으로 바인드 됩니다. Rvalue는 rvalue 참조에 우선적으로 바인드 됩니다.
· 일반변수는 참조타입에 바인드 되는 것을 좋아 하지 않습니다.
예제에서 위의 규칙이 어떻게 처리되는지 살펴 보면,
· 초기화 규칙에 따라서 purr(up)는 purr(const string&) 나 purr(string&&) 함수는 호출 될수 없습니다. up변수는 lvalue 이기 때문에, lvalue 참조타입을 파라메터로 가지는 purr(const string&) 함수를 호출 하려합니다. up 는 (변경가능한) lvalue변수기 때문에, purr(cont string&&)함수가 호출 될수있지만, purr(const string&)함수가 호출 됩니다.
· purr(down) 함수는, down 변수는 const lvalue 이기 때문에 purr(const string&) 함수가 호출 됩니다.
· purr(strange()) 함수는 초기화 규칙에 의해 purr(const string&), purr(string&&) 함수는 호출 될 수 없습니다. strange() 함수는 rvalue를 리턴 하기때문에, purr(string&&) 함수가 호출 됩니다 .
· purr(charm())에서, charm()함수는 const rvalue를 리턴 하기 때문에 purr(string&&)함수를 호출 할 수 없습니다. 그래서 purr(const string&) 함수가 호출 됩니다.
알아두어야할 것은 const Type& 과 Type&& 타입을 오버로드 함수를 만들었을때, rvalue는 Type&&에 바인드되어지고, 그 외는 const Type&로 바인드 되어집니다. 이것을 move semantic에서 overload set이라 부릅니다.
Important note: 값을 리턴 하는 함수는 예에서 strange()함수와 같이 Type 을 리턴 해야 합니다. Charm()함수와 같이 const Type을 리턴 해서는 안됩니다. 값을 리턴하는 함수가 const Type을 리턴 하게 되면 non-const 멤버함수를 호출할 수 없고, move semantic 최적화가 적용 되지 않습니다.
회사 차장님이 보여주신 애자일 관련 동영상입니다.
"Head First Software Development" 에서 본 내용이 몇개 들어 있네요.
애자일 방법론 개발팀과 워터폴 방법론 개발팀이 일하는 방식을 재미있게 묘사하고 있습니다.
|
Get a quick overview of new security features in Windows 7, and changes to security features and technologies from Windows Vista.
|
|
Delve deep into the various aspects of deploying BitLocker Drive Encryption on computers running Windows 7 Enterprise or Windows 7 Ultimate from using certifications and smart cards to enabling BitLocker by using the command line.
|
|
Designed to help you become familiar with BitLocker Drive Encryption in a Windows 7 test environment, this guide details basic information and procedures you need to start configuring and deploying BitLocker in your organization.
|
|
Learn how to use the ActiveX Installer Service to manage the deployment of ActiveX controls by using Group Policy on computers in an organization.
|
|
This step-by-step guide is designed to help administrators become familiar with AppLocker by providing the instructions needed to set up AppLocker in a test lab environment. Each scenario provides basic information and procedures that administrators can use to start configuring and deploying AppLocker in their network environments.
|
|
Windows 7 gives you more control over the Security Messages and other Notifications you may or may not want to receive. Learn how, for starters, you can configure how notifications are handled on the Taskbar__choosing to hide certain types of notifications, such as Action Center messages, Network messages, Windows Update Automatic Updates messages, and so on.
|
|
Learn how to slipstream a Forefront Client Security engine update into your System Center Configuration Manager (SCCM) or script-based initial Client Security client deployment, so that you are deploying the most up to date engine.
|
|
Internet Explorer Enhanced Security Configuration places your server and Internet Explorer in a configuration that decreases the exposure of your server to potential attacks that can occur through Web content and application scripts. Learn more about this configuration and browser security best practices.
|
| • | |
| • | |
| • | |
| • | |
| • | |
| • |
| • | |
| • | |
| • |
| • |


