c++ - 声明不兼容
问题描述
我即将学习一点C++。我习惯了 Java 和 Python,我对整个标题内容感到非常困惑。
实用程序.cpp:
#include "Utils.h"
#include <string>
#include <direct.h>
#include <fstream>
#include <Windows.h>
#include <iostream>
using namespace std;
string dst = "";
string Utils::getDst() const {
return dst;
}
string Utils::getExePath() {
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
return string(buffer);
}
char* Utils::getCwd() {
return _getcwd(0, 0);
}
实用程序.h:
#ifndef UTILS_H
#define UTILS_H
#include <string>
#include <direct.h>
#include <fstream>
#include <Windows.h>
#include <iostream>
class Utils
{
private:
string dst;
public:
string getDst() const;
char* getCwd();
string getExePath();
};
#endif
调试不是问题。但它运行的是旧版本,我没有实现#getDst()
and #getExePath()
。构建项目时会发生这些错误,导致项目失败:
解决方案
感谢伊戈尔·坦德尼克。我的问题出在我的 Utils.h 中。
新的 Utils.h:
#ifndef UTILS_H
#define UTILS_H
#include <string>
#include <direct.h>
#include <fstream>
#include <Windows.h>
class Utils
{
private:
std::string dst;
public:
std::string getDst() const;
char* getCwd();
std::string getExePath();
};
#endif
我忘记了std::
字符串之前的内容。using namespace std;
我也可以添加Utils.h
推荐阅读
- apache-spark - 如何根据多个排名条件合并到 Delta Lake?
- c# - 如何通过 Serializer 正确动态创建自定义 JSON
- java - zip4J 异常解压缩密码保护的 zip 文件
- html - 简单灯箱未正确缩放
- wolfram-mathematica - 在 Mathematica 中设置默认绘图设置——颜色、虚线、线宽
- kubernetes - 如何在 istio 1.8.3 中收集 Envoy 输出的访问日志
- css - 如何以跨浏览器的方式在 CSS 中指定日文字体?
- python - 在线“Zybooks”编码中的 Python EOFerror
- python - 接收空数据帧以解决纸浆优化问题
- oracle - 我可以为 ASM 创建 Oracle 数据库链接吗?