I’m likely just doing something dumb, but I can’t figure it out. I have a class called VariableList thats defined in a .h and a .cc file as follows: (some of the .cc file ommitted)
Header:
#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 file
#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
I’m attempting to use it as follows:
#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;
}
but whenever I try to compile, the compiler says “undefined reference to VariableList::VariableList()” as though it’s not seeing my .cc file. Is there more I need to do for it to see my definititions in the .cc file?
Are you adding all your .cc files when compiling?
g++ -o myExecuatable file1.cc file2.cc file3.cc ...