Undefined reference to:

Hi guys! I'm trying to get a vector of pointers, that point to an index vector to sort a vector of doubles (it sounds round about, but I will actually end up applying the index over three of four arrays), and when passing my vectors, I keep getting undefined reference errors. Any help would be appreciated.

OS, XP SP 2
compiler g++ (running under cygwin)
note: it compiles fine under wxdev, but i've had wx miss errors before...

main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

#include <vector>
using std::vector;

#include "a2sort.h"

int main()
{
    int i;
    vector<int> index;
    vector<int*> pIndex;
    double blah[] = { 2.5, 9.2, 7.55, 3.64, 93.2, 35.22, 432.4};
    for( i = 0; i < 7; ++i )
        index.push_back( i );
    for( i = 0; i < 7; ++i )
        pIndex.push_back( &index[i] );

    sort sorter;

    sorter.sortByAverage( pIndex, index, blah);
    for( int j = 0; j < 7; ++j )
        cout << blah[*pIndex.at(j)] << endl;
    string aVar;
    cin >> aVar;
}


a2sort.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef A2SORT_H
#define A2SORT_H

#include <string>
using std::string;

#include <vector>
using std::vector;

#include <iostream>
using std::cout;
using std::endl;

class sort
{
    public:
        //void sortByName( vector<int*>&, vector<int> &, string[] );
        void sortByAverage( vector<int*> pData ,vector<int> &data, double average[] );
};

#endif 


a2sort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "a2sort.h"

void sort::sortByAverage( vector<int*> pData ,vector<int> &data, double average[] )
{
    int i, j, *tmp;
    for( i = 1; static_cast<unsigned int>(i) < data.size(); ++i )
    {
        tmp = pData[i];

        j = i;

        while( ( j > 0 ) && ( average[ j - 1 ] < average[ i ] ) )
        {
            pData[j] = &data[ j - 1 ];
            --j;
        }

        pData[j] = tmp;
    }
}


the error:

1
2
3
4
/cygdrive/c/DOCUME~1/student/LOCALS~1/Temp/cckzOzx9.o:main.cpp:(.text+0x311): un
defined reference to `sort::sortByAverage(std::vector<int*, std::allocator<int*>
 >, std::vector<int, std::allocator<int> >&, double*)'
collect2: ld returned 1 exit status 


thanks for any help guys!
Last edited on
Hi, you have pasted main twice and missed a2sort.h:-(
So i have, fixed now =) any ideas?

UPDATE: fixed. Installed cygwin on my base machine (rather than on one of my Virtual comps) and it works perfectly.
Last edited on
Topic archived. No new replies allowed.