gpt4 book ai didi

C++ 找不到类方法定义

转载 作者:行者123 更新时间:2023-11-28 03:51:40 25 4
gpt4 key购买 nike

我可能只是在做一些愚蠢的事情,但我想不通。我有一个名为 VariableList 的类,它在 .h 和 .cc 文件中定义如下:(省略了一些 .cc 文件)

标题:

#pragma once
#ifndef _VARIABLELIST_H_
#define _VARIABLELIST_H_
#include "Variable.h"
#include <algorithm>
#include <vector>
using namespace std;

class VariableList
{
public:
VariableList(void);
VariableList(const VariableList &other, bool setLiveness = false, bool liveVal = false);
void Add(const simple_instr* instr);
void Add(Variable var);
void SortAndRemoveDuplicates();
bool CompareLiveness(const VariableList &var);

int size();
vector<Variable>::iterator begin();
vector<Variable>::iterator end();

//Operator Overloads
Variable& operator[] (int i);

protected:
int currentID;
vector<Variable> variableList;
void Add(const simple_reg* ref, bool checkForDuplicated = true);
private:
};
#endif

.cc 文件

#include "VariableList.h"
VariableList::VariableList(void)
{
currentID = 0;
}

VariableList::VariableList(const VariableList &other, bool setLiveness = false, bool liveVal = false) //: currentID(0), variableList(other.variableList)
{
currentID = 0;
variableList(other.variableList);
if (setLiveness)
{
for( int i = 0; i < size(); i++ )
variableList[i].isLive = LiveVal;
}
}

//Rest Omitted as it doesnt matter for the problem I'm having

我正在尝试按如下方式使用它:

#include <iostream>
extern "C" {
#include <simple.h>
}
#include<vector>
#include<string>
#include "Instruction.h"
#include "Variable.h"
#include "VariableList.h"
using namespace std;
class VariableList;
simple_instr* do_procedure (simple_instr *inlist, char *proc_name)
{
Instruction inst(*inlist);
Variable var;
cout << var.GetID();
VariableList varList;
return inlist;
}

但每当我尝试编译时,编译器都会说“对 VariableList::VariableList() 的 undefined reference ”,就好像它没有看到我的 .cc 文件一样。我是否需要做更多工作才能在 .cc 文件中看到我的定义?

最佳答案

编译时是否添加所有 .cc 文件?

g++ -o myExecutable file1.cc file2.cc file3.cc ...

关于C++ 找不到类方法定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5265255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com