Skip to content

Instantly share code, notes, and snippets.

@dazfuller
Created November 6, 2011 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dazfuller/1343485 to your computer and use it in GitHub Desktop.
Save dazfuller/1343485 to your computer and use it in GitHub Desktop.
Ignoring the Voices: C++11 Example - Using auto as a Return Type
#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;
}
class Test
{
public:
enum TestEnum { One, Two, Three };
void SetField(TestEnum t);
TestEnum GetField();
private:
TestEnum _field;
};
@dazfuller
Copy link
Author

Compiled as follows:

g++ -std=c++0x -Wall -Werror -o auto_return auto_return.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment