I am getting an error I am unsure of how to deal with, when running my simple code. I have been over my code for the past hour, and swear that the syntax is correct.
This is just the beginning of a much larger project, and I haven't even got the basics right. The output is:
lloyd@lloyd-laptop:~/Desktop/Code/Viscious Walker$ g++ vicioustest.cpp -o viciousResults /tmp/cceanGG8.o: In function `main': vicioustest.cpp:(.text+0x31): undefined reference to `ViciousWalker::ViciousWalker(int, int, int, int)' collect2: ld returned 1 exit status
Header:
#ifndef Vic
#define Vic
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <limits.h>
using namespace std;
class ViciousWalker {
public:
/*Initialising Constructor*/
ViciousWalker(int = 2, int=1, int=1, int=1);
/*Set Functions*/
void setArray(int,int);
void setTimeStep(int);
/*Get Functions*/
int getArray();
int getTimeSteps();
private:
int arrayRow, arrayCol;
int timeSteps;
int numberOfWalkers;
};
#endif
Class file:
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <limits.h>
#include "vicious.h"
using namespace std;
/*Constructor*/
ViciousWalker::ViciousWalker(int R, int C, int t, int n){
arrayRow=R;
arrayCol=C;
timeSteps=t;
numberOfWalkers=n;
};
/*Set Functions*/
void ViciousWalker::setArray(int a, int b){
if (a>=1 && b>=1 ) {
arrayRow = a;
arrayCol = b;
}
else {
cout<<"Array parameters need to be greater than zero."<<endl;
exit( EXIT_SUCCESS );
}
};
/*void ViciousWalker::setArray(int a){
if (a>=1) {
int arrayRow = a;
int arrayCol = a;
}
else {
cout<<"Array parameters need to be greater than zero."<<endl;
exit( EXIT_SUCCESS );
}
};*/
void ViciousWalker::setTimeStep(int i){
if (i>=1) {
timeSteps = i;
}
else {
cout<<"Number of time steps need to be greater than zero."<<endl;
exit( EXIT_SUCCESS );
}
};
Main function file:
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <limits.h>
#include "vicious.h"
int main(){
ViciousWalker deathRing(4,3,100,3);
//deathRing.setArray(4,3);
return 0;
}
Any help at all would be greatly appreciated! :D


Sign In
Create Account


Back to top









