此声明没有存储类或类型说明符

编译器报错提示 此声明没有存储类或类型说明符xx does not name a type

个人原因

因为我在头文件中运行了如下语句

struct EXAMPLE examples;
examples.input = "hello world"

但是 函数外只能定义全局变量或者对象 ,而不能执行语句及调用函数 。

可以改为

struct EXAMPLE examples = {.input = "hello world"};   

但是注意C语言中结构体初始化时,对于内部元素的顺序没有要求,但是C++不一样。
因为C++结构体初始化时,必须按照定义的顺序进行初始化,不能够跳过其中内容而初始化其他选项,或者定义的顺序先后有问题。
否则会报错:sorry, unimplemented: non-trivial designated initializers not supported

c++最好这么写

struct EXAMPLE examples = {"hello world"};   

原因2

i just had this problem, and like Arckaroph have said : the problem is that when we include
a header file in a source code file, and we use in it the directive #ifndef, we can't include
it again in a header file to give a type of it's included class to a variable in source code file

example :

class1.h contains Class1 class2.h contains Class2 class2 have a private variable V with
class1 type if we include class1.h in class2.CPP we can't include it in class2.h to give V a class1 type.

so we put in class2.cpp class2.h before class1.h or we delete class1.h from class2.cpp

原文地址:https://www.cnblogs.com/friedCoder/p/12239966.html