我可能只是在做一些愚蠢的事,但我无法弄明白。我有一个名为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()的未定义引用”,好像它没有看到我的.cc文件。我还需要做些什么来查看我在.cc文件中的定义吗?
答案 0 :(得分:2)
您在编译时是否添加了所有.cc文件?
g++ -o myExecuatable file1.cc file2.cc file3.cc ...