【问题标题】:Errors in main.cpp after delcaration of .h files声明 .h 文件后 main.c++ 中的错误
【发布时间】:2016-01-05 18:36:04
【问题描述】:

这是我的问题:

#include<iostream>
#include<fstream>
#include<memory>
#include<stdio.h>
#include<sstream>
#include<utility>
#include<algorithm>
#include<vector>

#include "classes.h"
#include "firstfunction.h"
#include "secondfunction.h"
#include "third function.h"

using namespace std;


int main(){
  // do cool stuff
}

但是当我编译时我得到了错误(都在同一行,使用命名空间之一)

错误:只有构造函数采用成员初始值设定项 错误:预期在“使用”之前识别 错误:使用前应为“{”

如果我尝试删除“using namespace std”,我仍然会使用 'int' 而不是 using。

其余代码似乎编译没有错误!你有什么想法吗?

【问题讨论】:

  • 如果这是您唯一的源文件,那么您在其中一个头文件中有错误。
  • 您应该做的第一件事是注释掉所有属于您的头文件,注释掉main 中的“很酷的东西”并重新编译。然后如果代码编译成功,把每一个都引入程序中重新编译,直到编译失败。
  • 问题很可能出在third function.h

标签: c++ header include project


【解决方案1】:

您为什么不尝试删除“第三个function.h”中的空格?我不知道,但也许将文件名更改为“thirdfunction.h”或“third_function.h”会起作用。当您必须处理空格时,C++ 是一个非常糟糕的人。此外,您应该检查 .h 文件中的实现(从“classes.h”到“third function.h”),因为错误可能在其中一个文件中。我应该先看看它是否可以更改“第三个 function.h”的名称,然后深入研究您的其他 .h 文件...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多