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.

If you intended to correct an error in the post then please contact us.

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


	//Overloaded Operators

	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


	//Overloaded Operators

	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 this post


Link to post
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()
{

}

/*
GetData
This Function loads in the Appropriate Data (File Header) for an InAir.x
file.
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;
}

/*
PutData
This Function Writes Out the Appropriate Data (File Header) for an InAir.x
file.
Then It Appends the Vector Data to the Current InAir Matrix
*/

void CAirClass::PutData(std::vector<int>* vec)
{

}

/*
DumpInAirData
This Function is primarily to be used as a debugging tool, it will
dump 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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites