#### Archived

This topic is now archived and is closed to further replies.

# Are My Abstract & Real Class Declarations ok ?

This topic is 5310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a problem with my declaration of my Abstract Class / Normal Class as follows ?

class BaseCls
{
//Private Variables are in here

private:
protected:
float fVersion;	//The Version of this Class

//public Functions and Data go in here

public:
virtual ~BaseCls();
virtual void GetData(int Beam, std::vector<int>* vec)=0;	//Load in the Data

virtual void PutData(std::vector<int>* vec)=0;	//Write out the Data

bool operator== (BaseCls T);
BaseCls& operator=(const BaseCls &T);
bool operator< (BaseCls T);
//Debug Function, Drop all Data to Console

virtual void DumpData()=0;
};

class CAirClass : public BaseCls
{
//Private Variables are in here

protected:

//public Functions and Data go in here

public:
CAirClass();
CAirClass(const CAirClass &T);
~CAirClass();
void GetData(int Beam, std::vector<int>* vec);	//Load in the Data

void PutData(std::vector<int>* vec);	//Write out the Data

bool operator== (CAirClass T);
CAirClass& operator=(const CAirClass &T);
bool operator< (CAirClass T);

void DumpData();	//Function to Dump all inair Data to the screen

};


As when I compile these files, and the associated .cpp files (using DJGPP) I get 5 errors all of the following format; AirClass.cpp: undefined reference to ''BaseCls::~BaseCls [not-in-charge]()'' as well as 2 lines, 1 claiming undefind reference to ''vtable for BaseCls and 1 undefined reference to ''typeinfo for BaseCls Any help would be appreciated, Bp.

##### Share on other sites
show us the code in the cpp that is causing the error!

##### Share on other sites
I am still looking at isolating the code to see if any function is causing the problem. initially I wondered if there was anything obvious in my declarations that was wrong.

##### Share on other sites
OK, it seems I get the same errors no matter which functions I comment out, so apologies for dropping the whole lot in here

  #include "AirClass.h"#include <stdio.h>#include <ios>/*Object Construction and Destruction*/CAirClass::CAirClass(){	//Get the Root File Path and Name for this Object	//As this is the Class For the Header of Each Air File, 	//The Type of File for get_optfile() is 9//	get_optfile(9,1,&BaseFName.c_str());	//Temporary Code	baseFName = "D:/Data/InAir.";	fVersion = 0.1f;}CAirClass::CAirClass(const CAirClass &T){		nBeamNum = T.nBeamNum;		nRows = T.nRows;		nCols = T.nCols;		rTheta = T.rTheta;		rPhi = T.rPhi;}CAirClass::~CAirClass(){}/*GetDataThis Function loads in the Appropriate Data (File Header) for an InAir.xfile.Then It Appends the Vector Data to the Current InAir Matrix*/void CAirClass::GetData(int Beam, std::vector<int>* vec){	std::fstream *fs = new std::fstream;	//Convert the filenumber into a text string	char* filenumber = "99";	itoa(Beam,filenumber,10);	//Create the full Name of the File that is Required	std::string fn = baseFName + *filenumber;	//Ask the Filestream Object to throw an exception on Failure		fs->exceptions(std::ios::badbit|std::ios::failbit);	try		{			fs->open(fn.c_str(),std::ios::in|std::ios::binary);		fs->setf(std::ios_base::dec);		*fs>>nBeamNum;		*fs>>nRows;		*fs>>nCols;		//Read in the floating point data		fs->setf(std::ios_base::fixed);		*fs>>rTheta;		*fs>>rPhi;		//Read in Integer Data for Air Matrix		fs->setf(std::ios_base::dec);			int temp;			printf("Getting Matrix Data %i\n",(int)vec->size());		while (!fs->eof())		{			*fs>>temp;			vec->push_back(temp);		}	}	catch(std::ios::failure)	{		printf ("Exception Thrown.\nCannot Find File %s\n",fn.c_str());	}		fs->close();	delete fs;}/*PutDataThis Function Writes Out the Appropriate Data (File Header) for an InAir.xfile.Then It Appends the Vector Data to the Current InAir Matrix*/void CAirClass::PutData(std::vector<int>* vec){}/*DumpInAirDataThis Function is primarily to be used as a debugging tool, it willdump all loaded data to the console when called*/void CAirClass::DumpData(){	printf("Dumping InAir Data Object (Version %2.2f)\n",fVersion);	printf("Beam Number = %i, Matrix Rows = %i, Matrix Columns = %i\n, Theta ? = %1.5f, Phi ? = %1.5f\n"		,nBeamNum,nRows,nCols,rTheta,rPhi);}/*Overloaded Operators*/  bool CAirClass::operator== (CAirClass T){	//Need to compare all elements to see if equal here	return true;}bool CAirClass::operator< (CAirClass T){	//Need to compare what to see if this object is less	return true;}CAirClass& CAirClass::operator=(const CAirClass &T){	if (this != &T)	{		nBeamNum = T.nBeamNum;		nRows = T.nRows;		nCols = T.nCols;		rTheta = T.rTheta;		rPhi = T.rPhi;	}	return *this;}

Thanks for any help you can offer. Only thing I can say is that this used to work until I decided to create an abstract class to inherit from :-/

Bp.

##### Share on other sites
Its probably due to the fact that there is no function body for the virtual destructor in the base class. Just make it either blank or turn it into a pure virtual function(Depends whether you want derived classes to HAVE to define a destructor or not)

James

##### Share on other sites
OK, well you learn something each day
if I made it a Pure Virtual it reduced the errors, but by making it an empty inline destructor it worked a treat.

Thanks
Bp.

##### Share on other sites
and what line is the error?

##### Share on other sites
The Error was in the definition of the Abstract class, and so the error messages were decieving, which was why I ended up asking for help in here again.

Looks like you & James are the 2 main contributors in this forum (certainly to me anyway )

Thanks both for all the posts you have made to my questions now and in the past.

Bp.

• ### Forum Statistics

• Total Topics
628642
• Total Posts
2983991

• 9
• 10
• 20
• 20
• 13