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

编译器报错提示 此声明没有存储类或类型说明符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

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

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

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/192484

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午6:03
下一篇 2023年2月12日 下午6:04

相关推荐