繁体   English   中英

C ++体系结构x86_64的未定义符号

[英]C++ Undefined symbols for architecture x86_64

我是C ++的新手,正在尝试将文本保存到文本文件中。 但是,当我运行该程序时,我不断从eclipse中收到此错误,并且无法弄清楚出了什么问题:

 Undefined symbols for architecture x86_64:
 "StorageSave::execute(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
 _main in SpendTracker.o

这是我的代码:

StorageSave.h:

#include <fstream>
#include <string>
#include <vector>
#include "Account/Account.h"

#ifndef STORAGE_STORAGESAVE_H_
#define STORAGE_STORAGESAVE_H_

class StorageSave {
public:
    StorageSave();
    virtual ~StorageSave();

    std::string execute(std::string allData);
};

#endif /* STORAGE_STORAGESAVE_H_ */

StorageSave.cpp:

#include <iostream>
#include <fstream>
#include "StorageSave.h"

StorageSave::StorageSave() {
    // TODO Auto-generated constructor stub

}

StorageSave::~StorageSave() {
    // TODO Auto-generated destructor stub
}

std::string execute(std::string allData) {

    std::ofstream file("hey.txt");
    //std::ofstream *fileptr = &file;

    if(!file.is_open()) {
        std::cout << "Unable to open file." << std::endl;
    } else {
        std::string textData = "test";
        file << textData;
        file.close();
    }

    return "";
}

我想你应该转

std::string execute(std::string allData) {

进入

std::string StorageSave::execute(std::string allData) {

您正在使用execute作为成员函数并声明了它,但已实现为自由函数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM