0

I'm just starting an assignment for school and I'm getting the following error:

The Error

I don't know why this is happening. I've included the class header and I'm not using any fancy methods from other classes, just trying to make an object of the class to test the basics of the code. All of these files are in the same project on code blocks, the file sturcture is here.

This is my code, can anyone point out what I'm doing wrong, I'm just trying to start the assignment.

Main Method

#include <iostream>
#include "sorting.h"
using namespace std;

int main()
{
    sorting<int> object;
}

Header

#ifndef SORTING_H
#define SORTING_H

template <class T>
class sorting
{
    public:
        sorting();
        ~sorting();
    private:
};
#include "..\src\sorting.cpp"
#endif // SORTING_H

Implementation

#include "sorting.h"
#ifdef _SORTING_H_
template<class T>
sorting<T>::sorting()
{
    //ctor
}
template<class T>
sorting<T>::~sorting()
{
    //dtor
}
#endif
  • 1
    don't include a cpp file. – Daniel A. White Feb 13 '16 at 23:27
  • My textbook suggests doing this for template classes though. @DanielA.White EDIT I tried your suggestion and got the same error as I described above. – Darcy Olson Feb 13 '16 at 23:34
  • @DarcyOlson Put that textbook in the bin, or read twice thourughly. – πάντα ῥεῖ Feb 13 '16 at 23:46
  • For whatever reason our professor insists on having separate implementation and header files. I'm told that it's more common to define your functions inside the header when working with templates. Is there any way I can make it work with separate header and implementation files? @πάνταῥεῖ – Darcy Olson Feb 14 '16 at 00:07
  • oblige him, but in the .cc file, only have the one line including the header file. In the linker do not include the .o, if it even produces one. Then put all the stuff you think might go into the cc file into the hh file. – 2785528 Feb 14 '16 at 01:23
  • @DarcyOlson It's possible to have the implementation in a separate file, that is included from the header in turn. Usually you just choose a different file extension like `.tcc`. It's explained in the marked dupe. – πάντα ῥεῖ Feb 14 '16 at 03:55

0 Answers0