Hello,
I am developing a storage template using codeblocks and the project refuses to compile with a linker error 1. However it compiles alright from the command line (in debian).
It seems I cannot implement the constructor and destructor for the class as it does not recognise them.
Here's the storage file with CNode defined, it trips up with the definition of the constructor/destructor, it seems the IDE thinks there's two constructors and two destructors.
#include <stdlib.h>
#include "errors.h"
#ifndef STORAGE_H_INCLUDED
#define STORAGE_H_INCLUDED
namespace Storage {
using namespace Errors;
using namespace std;
template <class Type>
class CNode{
public:
CNode(Type TheData);
~CNode();
Type ReturnData();
private:
Type *ReturnPointerToData();
Type *m_ptrData;
};
template <class Type>
CNode<Type>::CNode(Type TheData)
{
// attempt to allocate memory for node
m_ptrData=(Type *) malloc(sizeof(TheData));
// if successfull
if (m_ptrData)
{
*m_ptrData=TheData; // assign what data pointer points at to data value
}
else
{
throw Errors::errrOutOfMemory; // report out of memory
}
}
// destructor
template <class Type>
CNode<Type>::~CNode()
{
free((void* ) m_ptrData);
m_ptrData=NULL;
}
// return data pointed to by data pointer
template <class Type>
Type CNode<Type>::ReturnData()
{
return *ReturnPointerToData();
}
// return POINTER to dataa
template <class Type>
Type *CNode<Type>::ReturnPointerToData()
{
return m_ptrData;
}
}
#endif // STORAGE_H_INCLUDED
As I can successfully compile this from the command line with g++ I believe this is a codeblocks error.
I am using svn build rev 10637 (2015-12-29 16:30:44) gcc 4.9.2 Linux/unicode - 64 bit.
Thanking you in advance,
Jonathan.