eclipse: undefined reference to `NR::sort(NRVec<double>&)'

Jan 16, 2012 at 12:02am

This is straight from Numerical Recipes in C++. But hitting snag in eclipse:

Problem:
Description Resource Path Location Type
undefined reference to `NR::sort(NRVec<double>&)' xsort.cpp /xsort/src line 33 C/C++ Problem

Source:

#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include "..\mylib\nr.h"
#include "..\mylib\nrtypes.h"
#include "..\mylib\nrtypes_lib.h"
#include "..\mylib\nrutil_val.h"
#include "..\mylib\print_array.h"


using namespace std;


// Driver for routine sort

int main(void)
{
const int NP=100;
string txt;
int i;
Vec_DP a(NP);
ifstream fp("tarray.dat");

if (fp.fail())
NR::nrerror("Data file tarray.dat not found");
getline(fp,txt);
for (i=0;i<NP;i++) fp >> a[i];
fp.close();
cout << endl << "original array:" << endl;
cout << fixed << setprecision(2);
print_array(a,10,7);
NR::sort(a);
cout << endl << "sorted array:" << endl;
print_array(a,10,7);
return 0;
}

from nr.h
void sort(Vec_IO_DP &arr);

Please let me know if you see the issue or what additional data you need to help.

Thanks
Jan 16, 2012 at 8:23am
It would be nice to see:
1) code tags,
2) header for Vec_DP and Vec_IO_DP.

however, I can see that there is a type mismatch. sort accepts a Vec_IO_DP, while we are inserting a Vec_DP;
Jan 16, 2012 at 8:35am
Stewbond is right there seems to be type mismatch in sort .. which accepts .. NRVec and you are giving Vec_DP
Jan 16, 2012 at 1:34pm
Stewbond, bluecoder, thank you for reply.

I get same error if I replace Vec_DP w/ Vec_IO_DP

Here's code snippet of Vec_IO_DP def

typedef double DP;
typedef const NRVec<DP> Vec_DP, Vec_O_DP, Vec_IO_DP;

template <class T>
class NRVec {
private:
int nn; // size of array. upper index is nn-1
T *v;
public:
NRVec();
explicit NRVec(int n); // Zero-based array
NRVec(const T &a, int n); //initialize to constant value
NRVec(const T *a, int n); // Initialize to array
NRVec(const NRVec &rhs); // Copy constructor
NRVec & operator=(const NRVec &rhs); //assignment
NRVec & operator=(const T &a); //assign a to every element
inline T & operator[](const int i); //i'th element
inline const T & operator[](const int i) const;
inline int size() const;
~NRVec();
};
Last edited on Jan 16, 2012 at 1:40pm
Topic archived. No new replies allowed.