0

So I have a "base" class called "SortData". When I try to allow my other header file "InsertionSort.h" inherit this base class, I keep getting a class type redefinition error. What am I doing wrong?

Here's the base class header:

// SortData.h

#include <iostream>

using namespace std;

class SortData
{
public:
	SortData(int max=100);
	~SortData(void);

	int size() const;
	void randomize(int seed = 1);
	void printSome(const int num=10) const;

	virtual _int64 sort() = 0;

protected:
	long *theData;
	int maxSize;
};

And here's the header that's trying to inherit this base class:

// InsertionSort.h

#include "SortData.h"

class InsertionSort : public SortData
{
public:
	InsertionSort(int max=100);
	~InsertionSort(void);
	_int64 sort();

private:
	_int64 numops;
	void insertionSort(long theArray[], int n);
};
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by yongj
0

Are you including both in main.cpp? This could be your problem and the solution is to use preprocessor blockers

SortData.h

#ifndef SORTDATA_H
#define SORTDATA_H

class SortData
{


};

#endif

And do the same thing for InsertionSort.h but with a different blocker name

0

Yeah I just realized that...sorry for the waste of forum space :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.