no member function declaired in class

I'm getting the following error:


select.cpp:4: error: no member function 'select' declared in 'Sortings<int, intintCompare>'
select.cpp:7: error: no 'void Sortings<Elem, Comp>::select(Elem*, unsigned int)' member function declared in class 'Sortings<Elem, Comp>'

and I have no clue whats going on. I have other files the same exact way and they work, any help?

header file

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _SORTING_H_
#define _SORTING_H_

#include <iostream>
#include <cstring>
using namespace std;

template <class Elem, class Comp>
class Sortings
{
 public:
  static void merge(Elem *arr, unsigned int n);
  //  static void quick(Elem *arr, unsigned int n); do merge or this one
  static void select(Elem *arr, unsigned int n);
  static void shell(Elem *arr, unsigned int n);
  static void radix(Elem *arr, unsigned int n); // when using radix, Comp should be a class
  // with a static method "uintVal(...)" that gives an unsigned int representation of the item
 private:
  // These are all optional, add or remove as functions as you need
  static const unsigned int THRESHOLD = 3; // used by shell
  static const unsigned int RADIX = 16; // used by radix
  static void insert2(Elem *arr, unsigned int incr, unsigned int n);
  static void swap(Elem *arr, unsigned int, unsigned int);
  static void mergeRecurse(Elem *arr, Elem tmp[], unsigned int l, unsigned int r);
};

class intuival
{
public:
  static unsigned int uintVal(int n);
};

class intintCompare
{
 public:
  static bool lt(int, int);
  static bool gt(int, int);
  static bool eq(int, int);
};

class strstrCompare
{
 public:
  static bool lt(char*, char*);
  static bool gt(char*, char*);
  static bool eq(char*, char*);  
};

#endif 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "sorting.hh"

template class Sortings<int,intintCompare>;
template void Sortings<int,intintCompare>::select(int*, unsigned int);

template<class Elem, class Comp>
void Sortings<Elem,Comp>::select(Elem* arr, unsigned int n)
{
int i,j,min;
for(i=0;i<n;i++)
min = i;
for (j = 1; j<n && Comp::lt(arr[j], arr[min];j++)
min = j
swap(arr,min,i);
}
Uh, all your member functions are static. You should probably go look up what that means.
I can't touch the header file. that was given to me like that by my professor.
It's not clear what are you doing?

Are you providing the implementation for the methods declared in the header file?

It would help if you indented your code.
Last edited on
I am implementing the methods in the header file. I have them all started off the same way
1
2
3
4
5
6
#include "sorting.hh"

template class Sortings<int,intintCompare>;
template void Sortings<int,intintCompare>::select(int*, unsigned int);

template<class Elem, class Comp>


obviously formatting it to each method. This method is the one I'm getting a problem for though. So I don't understand what's wrong.
The syntax isn't quite right.

You have to complete the implementation like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
template <class Elem, class Comp>
void Sorting<Elem, Comp>::merge(Elem *arr, unsigned int n)
{
    // place your implementation here
}

template <class Elem, class Comp>
void Sorting<Elem, Comp>::select(Elem *arr, unsigned int n)
{
    // place your implementation here
}

// and so on ... 


If you want to preinstantiate the class for Sortings<int, intintCompare>, you add this at the end of the .cpp file.
 
template class Sortings::<int, intintCompare>;


There's an example here:
http://www.cplusplus.com/forum/unices/7252/#msg33687
its still not finding the function. it keeps saying that select is not a member function declared in Sortings<Elem,Comp> even though its right there in the header file. I don't understand.
can you please list a skeleton view of your header file - ie minus the inner implementations (if they do currently exist) of the Sorting class methods?
So I just moved all files into another directory, and that caused it to work as is. Weird.
Topic archived. No new replies allowed.