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

时间:2015-12-11 15:53:59

标签: c++ eclipse

我是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 "";
}

1 个答案:

答案 0 :(得分:6)

我认为你应该转

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

进入

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

您正在使用execute as member function并声明它,但是实现为自由函数