There are quite a few posts like this on Stack Overflow, but most of them pertain to Xcode, and I cannot replicate their solutions. I have a Heap.h, Heap.cpp, and main.cpp file and whenever I try to run main.cpp with g++ main.cpp Heap.cpp, it gives me:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File Heap.h
#ifndef _HEAP_H_
#define _HEAP_H_
template<class T>
class Heap{
private:
struct Node{
T *dist;
T *v;
bool operator==(const Node& a){
return *dist == *(a -> dist);
}
bool operator!=(const Node& a){
return (!(*dist == *(a -> dist)));
}
};
Node *container;
int size;
int curSize;
T sourceV;
public:
Heap();
Heap(int inSize, T inSourceV);
};
#endif
File Heap.cpp
#include <iostream>
#include <vector>
#include <limits>
#include "Heap.h"
using namespace std;
template<class T>
Heap<T>::Heap(){
cout << "hello" <<endl;
}
template<class T>
Heap<T>::Heap(int inSize, T inSourceV){
size = inSize;
container = new Node[size];
curSize = 0;
sourceV = inSourceV;
int maxVal = numeric_limits<int>::max();
for (int i = 1; i < size; i++){
container[i].dist = &maxVal;
container[i].v = &maxVal;
}
}
File main.cpp
#include "Heap.h"
#include <iostream>
using namespace std;
int main(){
Heap <int> h;
}
It is strange I have another project that contains bst.h, bst.cpp, and main.cpp, and those run fine. The difference between these two projects is that the bst I implemented is not a templated class.
I also saw another similar post that mentioned something about changing bitcode settings, but where can I access that from?
I'm running Xcode 7.1. Apple LLVM version 7.0.0 (clang-700.1.76).
Target: x86_64-apple-darwin14.5.0
Thread model: posix