Class-Wide `using` alias as return type issuing compiler error

83 Views Asked by At

In order to keep some code readable and avoid typos, I'm using the following statement in the public section of a class definition in a header file:

using Assembly_Tuple = std::tuple <std::vector <std::string>, Trigger_Map, Attribute_Map>;

I'm declaring a function in the header file with Assembly_Tuple as a return type:

Assembly_Tuple merge_node_attributes(const std::string& node_name, std::string tmpl_name="");

And I'm defining the function in the source file:

Widget_Server_Interface::Assembly_Tuple 
Widget_Server_Interface::merge_node_attributes(const std::string& n, const std::string& t)
{
    //...
}

But when I try to compile, I get the following error:

src/WidgetServer/WidgetServerInterface.cpp:31:1: error: ‘Assembly_Tuple’ in ‘class Widget_Server_Interface’ does not name a type

However, inside definitions, there aren't any problems.

If I change that line to the egregious:

std::tuple<std::vector<std::string>, Trigger_Map, std::map<int,Node_Value>>
Widget_Server_Interface::merge_node_attributes (...) {...}

it's fine. Clearly the problem is using the alias outside of scope, even though it's public and I'm explicitly calling on the class namespace.

I looked in Bjarne's book but he doesn't mention anywhere whether or not this is legal.

This is using gcc 4.7.

Mostly, I would just like to know why this isn't valid.

0

There are 0 best solutions below