I have been trying to get my code to compile for a while. Kept looking online for a solution to my problem but I didn't find one. Some help would be appreciated.
Here are some of the files that I have:
gate.h
#ifndef GATE_H
#define GATE_H
#include <vector>
class Gate {
private:
std::vector<int> inWires, outWires;
char function;
public:
Gate (char function, const std::vector<int>& inputWires, const std::vector<int>& outputWires);
};
#endif
gate.cpp
#include "gate.h"
Gate::Gate (char functionality, const std::vector<int>& inputWires, const std::vector<int>& outputWires) {
function = functionality;
inWires = inputWires;
outWires = outputWires;
}
circuit_file_reader.h
#ifndef CIRCUIT_FILE_READER_H
#define CIRCUIT_FILE_READER_H
#include <string>
#include <iostream>
#include <vector>
#include "circuit.h"
#include "gate.h"
Circuit readCircuit(std::string filename);
#endif
circuit_file_reader.cpp
#include "circuit_file_reader.h"
Circuit readCircuit (std::string filename) {
std::vector<int> iw (1, 7);
std::vector<int> ow (1, 8);
Gate g0 ('a', iw, ow); // This is the problem
std::vector<Gate> gates;
// gates.push_back (g0);
return Circuit (gates, 0);
}
test_circuit_file_reader.cpp
#include <iostream>
#include <string>
#include "circuit_file_reader.h"
int main(int argc, char** argv) {
readCircuit("");
std::cout << "Test Worked!" << std::endl;
return 0;
}
Whenever I try to compile this code my compiler returns
circuit_file_reader.cpp:(.text+0xa5): undefined reference to `Gate::Gate(char, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&)' collect2: error: ld returned 1 exit status
Which is strange because the Gate constructor has been defined so why can't it see it?