zoukankan      html  css  js  c++  java
  • 此声明没有存储类或类型说明符

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

  • 相关阅读:
    菜鸟攻城狮4(基本语法)
    Spring 3.x 企业引用开发实战(陈雄华/林开雄)
    进击的菜鸟问题1(设置checkbox全选)
    Maven实战
    菜鸟攻城狮3(Holle World)
    菜鸟攻城狮2(JAVA开发环境)
    git基本使用
    跨域问题及解决跨域的方案
    原生ajax相关概念
    php服务器语言,MySQL数据库以及php怎么操作数据库
  • 原文地址:https://www.cnblogs.com/friedCoder/p/12239966.html
Copyright © 2011-2022 走看看