zoukankan      html  css  js  c++  java
  • 在调试C++程序是出现这个问题的解决方案illegal pure syntax, must be '= 0'

    笔者在调试c++的时候遇见了这个问题

    E:Data StructSqString新建 文本文档.cpp(5) : error C2258: illegal pure syntax, must be '= 0'
    E:Data StructSqString新建 文本文档.cpp(5) : error C2252: 'length' : pure specifier can only be specified for functions

    代码如下:

    #include<stdio.h>
    #include<malloc.h>
    typedef struct array
    {
    int length=50;

    }SqString;
    void main()
    {
    SqString st;
    }

    2、根据第一个错误,我们把length值设为0

    出现

    E:Data StructSqString新建 文本文档.cpp(5) : error C2252: 'length' : pure specifier can only be specified for functions

    MSDN提示错误C2252如下:'identifier' : pure specifier can only be specified for functions

    《C++编程思想》解释如下:不能这样初始化。因为定义结构体时,并未给其分配内存,所以初值是无法存储的。

    应该声明结构体变量后,手工赋值在结构体和类中不能对成员初始化。

    #include<stdio.h>
    #include<malloc.h>
    typedef struct array
    {
    int length;

    }SqString;
    void main()
    {
    SqString st;
    st.length=10;
    }

    这样是对的

  • 相关阅读:
    什么是tomcat集群?
    cmd黑客入侵命令大全
    Linix基本命令
    Windows CMD命令大全
    python 函数1
    Python 集合(set)使用
    python 数据字典应用
    python 数据运算
    python 数据类型(元组(不可变列表),字符串
    python 数据类型(列表)学习笔记
  • 原文地址:https://www.cnblogs.com/kwdeblog/p/5238104.html
Copyright © 2011-2022 走看看