Can't instantiate absstract class
Sorry, two more questions
Code:
#ifndef PERFECTSIM_PARSER
#define PERFECTSIM_PARSER
#include <string>
#include <d3dx9.h>
#include <sstream>
#include <iostream>
#include "tinyxml\tinyxml.h"
using namespace std;
template<class T>
class GetValue
{
protected:
virtual T get(TiXmlNode* pParent);
virtual T get_attribs(TiXmlNode* pParent) = 0;
};
class GetVector3 : public GetValue<D3DXVECTOR3>
{
public:
virtual D3DXVECTOR3 get(TiXmlNode* pParent);
virtual D3DXVECTOR3 get_attribs(TiXmlElement *element);
D3DXVECTOR3 get_vector3(TiXmlElement *element);
};
template<class T>
T GetValue<T>::get(TiXmlNode* pParent)
{
T attr;
if ( !pParent ) return attr;
TiXmlNode* pChild;
TiXmlText* pText;
int t = pParent->Type();
switch ( t )
{
case TiXmlNode::TINYXML_DOCUMENT:
break;
case TiXmlNode::TINYXML_ELEMENT:
attr =get_attribs(pParent->ToElement());
break;
case TiXmlNode::TINYXML_COMMENT:
break;
case TiXmlNode::TINYXML_UNKNOWN:
break;
case TiXmlNode::TINYXML_TEXT:
pText = pParent->ToText();
break;
case TiXmlNode::TINYXML_DECLARATION:
break;
default:
break;
}
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
get( pChild );
}
return attr;
}
#endif
Code:
// tutorial demo program
#include "stdafx.h"
#include "Parser.h"
/////////////////////////////////////
///
D3DXVECTOR3 GetVector3::get(TiXmlNode* pNode)
{
return GetValue::get(pNode);
}
D3DXVECTOR3 GetVector3::get_vector3(TiXmlElement* pElement)
{
return get_attribs(pElement);
}
D3DXVECTOR3 GetVector3::get_attribs(TiXmlElement* pElement)
{
if ( !pElement ) return D3DXVECTOR3();
GetValue::get(pElement);
D3DXVECTOR3 v;
pElement->QueryFloatAttribute("X", &v.x);
pElement->QueryFloatAttribute("Y", &v.y);
pElement->QueryFloatAttribute("Z", &v.z);
return v;
}
1) Can't instantiate abstract class of GetVector3.
2) Don't you think the coding is very redundant ?
Any help please?
Thanks
Jack
Re: Can't instantiate absstract class
Quote:
Originally Posted by
lucky6969b
1) Can't instantiate abstract class of GetVector3.
Just make sure all virtual methods have concrete implementations.
Re: Can't instantiate absstract class
Quote:
Originally Posted by
lucky6969b
2) Don't you think the coding is very redundant ?
The design seems very complicated. It's not clear to me what you want to achieve. Why do you have a template base class? Why does it have only protected virtual functions?
You should first think about what you want your program to do. Then think about a (class) design that can fulfill those requirements and only then you should start coding.
Re: Can't instantiate absstract class
When you overwrite a pure virtual function, it has to have the same signature. Otherwise you haven't actually overwritten it, you just have declared an unrelated virtual function.
Code:
virtual T get_attribs(TiXmlNode* pParent) = 0;
...
D3DXVECTOR3 GetVector3::get_attribs(TiXmlElement* pElement)
So the base class's get_attribs(TiXmlNode* pParent) function is still not defined in the derived class GetVector3 and hence the compiler says that the class contains undefined virtual functions and is an abstract class.