不死奇迹 2015-10-30 11:51 采纳率: 33.3%
浏览 3143

在头文件里定义一个string name; 变量,编译报错

//Parent.h
class Parent
{
public:
Parent(void);
~Parent(void);
private:
string name;
};

//main.cpp

#include
#include
#include "Parent.h"
using namespace std;

void main()
{
system("pause");
}

//Parent.cpp
#include "Parent.h"

Parent::Parent(void)
{
}

Parent::~Parent(void)
{
}

//编译器报错
错误 1 error C2146: 语法错误: 缺少“;”(在标识符“name”的前面) d:\用户目录\我的文档\visual studio 2012\projects\string\string\parent.h 8
错误 2 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int d:\用户目录\我的文档\visual studio 2012\projects\string\string\parent.h 8
错误 3 error C2146: 语法错误: 缺少“;”(在标识符“name”的前面) d:\用户目录\我的文档\visual studio 2012\projects\string\string\parent.h 8
错误 4 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int d:\用户目录\我的文档\visual studio 2012\projects\string\string\parent.h 8
5 IntelliSense: 未定义标识符 "string" d:\用户目录\我的文档\Visual Studio 2012\Projects\string\string\Parent.h 8

  • 写回答

9条回答 默认 最新

  • ysuwood 2015-10-31 00:11
    关注
    //Parent.h
     #pragma once
    #include <iostream>
    using namespace std;
    
    class Parent
    {
    public:
        Parent(void);
        ~Parent(void);
    private:
        string name;
    };
    
    //main.cpp
    #include "Parent.h"
    void main()
    {
        system("pause");
    }
    
    //Parent.cpp
    #include "Parent.h"
    Parent::Parent(void)
    {
    }
    Parent::~Parent(void)
    {
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题