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
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 ...
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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With