Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

structure does not name a type in c++

I get an issue while return type is structure

Example.h

class Example {
private:
    typedef struct connection_header {
        string url;
        string method;
    };

    static connection_header get_connection_header();
};

Example.cpp
connection_header Example::get_connection_header() {
    return NULL;
}

I am getting 'connection_header' does not name a type

may i know why is this error

like image 230
Kathick Avatar asked Mar 13 '13 07:03

Kathick


People also ask

Is struct a type in C?

A struct in the C programming language (and many derivatives) is a composite data type (or record) declaration that defines a physically grouped list of variables under one name in a block of memory, allowing the different variables to be accessed via a single pointer or by the struct declared name which returns the ...

Is structure name a pointer in C?

A pointer pointing to a structure is called structure pointer. Structures and pointers in C together help in accessing structure members efficiently. Structure pointer declaration is similar to declaring a structure variable using the struct keyword followed by the type of structure it will point to.

Can we declare structure without name?

Anonymous unions/structures are also known as unnamed unions/structures as they don't have names. Since there is no names, direct objects(or variables) of them are not created and we use them in nested structure or unions. Definition is just like that of a normal union just without a name or tag.

Is structure a keyword?

A structure is a key word that create user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.


1 Answers

You are using typedef without giving a name to the type. Just drop the typedef, it is not needed here:

struct connection_header {
    string url;
    string method;
};

Next, connection_header is declared inside of the Example class, so you need to fully qualify its name in the implementation when it is a return type:

Example::connection_header Example::get_connection_header()
like image 188
juanchopanza Avatar answered Sep 17 '22 05:09

juanchopanza