【发布时间】:2020-10-17 17:20:26
【问题描述】:
我有一个包含 3 个文件的程序,当 IrRun 通过 Code Runner 运行程序时,它不断打印错误。“Log.hpp”文件的图标是 C,而不是 C++。重命名为Log.h之类的也没关系,看来我在vscode中无法创建c++头文件。
这3个文件是:
- main.cpp
#include <iostream>
#include "log.hpp"
using namespace std;
int main() {
InitLog();
Log("Hello World");
return 0;
}
- log.cpp
#include "log.hpp"
#include <iostream>
void InitLog() {
Log("Initializing Log");
}
void Log(const char *message) {
std::cout << message << std::endl;
}
- log.hpp
#pragma once
void InitLog();
void Log(const char *message);
错误信息是:
main.cpp: In function 'int main()':
main.cpp:5:5: error: 'InitLog' was not declared in this scope
InitLog();
^~~~~~~
main.cpp:6:5: error: 'Log' was not declared in this scope
Log("Hello World");
需要帮助。
【问题讨论】:
-
这有关系吗? What are the dangers of using #pragma once? 我想你没有收到错误消息说
log.hpp not found。注意,如果header只包含函数声明,而没有#include其他header,可以多次包含。 -
我尝试使用那里显示的另一种方法(也就是使用 ifndef ect。)但错误仍然相同。
-
log.hpp在哪里?您的系统上是否有多个log.hpp文件? -
您调用包含的文件什么并不重要。
-
我的系统中没有任何其他头文件。
标签: c++ c visual-studio-code header-files