首页 > 解决方案 > 声明不兼容

问题描述

我即将学习一点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()。构建项目时会发生这些错误,导致项目失败: 例外

标签: c++header

解决方案


感谢伊戈尔·坦德尼克。我的问题出在我的 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


推荐阅读