Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
};
Owner

dazfuller commented Nov 6, 2011

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