Created
November 6, 2011 21:06
-
-
Save dazfuller/1343485 to your computer and use it in GitHub Desktop.
Ignoring the Voices: C++11 Example - Using auto as a Return Type
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 <iostream> | |
#include "auto_return.h" | |
void Test::SetField(TestEnum t) | |
{ | |
_field = t; | |
} | |
auto Test::GetField() -> TestEnum | |
{ | |
return _field; | |
} | |
int main() | |
{ | |
Test t; | |
t.SetField(Test::TestEnum::Two); | |
auto val = t.GetField(); | |
std::cout << val << 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
class Test | |
{ | |
public: | |
enum TestEnum { One, Two, Three }; | |
void SetField(TestEnum t); | |
TestEnum GetField(); | |
private: | |
TestEnum _field; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled as follows:
g++ -std=c++0x -Wall -Werror -o auto_return auto_return.cpp