-1

I've got header file with template class:

#ifndef BUBBLE_H
#define BUBBLE_H

#include "algorithm.h"

template <typename T>
class Bubble : public Algorithm <T> {
public:

    Bubble(T* in, int inSize) : Algorithm<T>(in, inSize){}

    void compute();
};

#endif // BUBBLE_H

if I put whole body of compute() class here everything works fine. But I would like to have it in cpp file. I wrote:

#include "bubbleSort.h" using namespace std;

template <typename T>
void BubbleSort<T>::compute(){   //(*)
    for (int i = 1; i<this->dataSize; i++){
        for (int j = this->dataSize-1; j>=i; j--){
            if(this->data[j] < this->data[j-1]) swap(this->data[j-1], this->data[j]);
        }
    } }

But I received error in line (*):

error: expected initializer before '<' token void BubbleSort::compute(){ ^

How I should fix it?

Malvinka
  • 1,185
  • 1
  • 15
  • 36

1 Answers1

1

It's because you're mixing up Bubble and BubbleSort, probably also the headers bubble.h and bubbleSort.h.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185