簡體   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