Strange include problem (src ok, but compile errors)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
paddy
Posts: 25
Joined: Tue Oct 23, 2007 12:30 pm

Strange include problem (src ok, but compile errors)

Post by paddy »

Hi there!

I've got a totally weird problem. I hope that someone can help me out.... I'm working on a project with the following self made classes:

Code: Select all

IGlobals.h (typedefs & #include <irrlicht.h>)
IElement.h (base class for class ISimulation)
ISimulation.h (a structure to save xml data)
IXML.h (Loads XML Data an saves it to a ISimulation instance)
ICore.h (visualization)
ISimulationManager.h (main prog)
IEventManager.h (handle key / GUI events)
IGUI.h (drawing buttons etc...)
now the includes in each class :

Code: Select all

IElement.h (incl. IGlobals.h)
ISimulation.h (incl. IElement.h)
-------------------------------------------------
ICore (incl. ISimulation.h)
IGUI (incl. IGlobals.h)
-------------------------------------------------
IEventManager(incl. ICore.h && IGUI.h)
-------------------------------------------------
ISimulationManager(incl. IEventManager.h)
-------------------------------------------------
IXML (incl. ISimulation.h)
the problem I have is the class IXML.h...

I wanted to include it in the IEventManager too, but
then I get these strange errors :

Code: Select all

1>Compiling...
1>IrrAOR.cpp
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(63) : error C2664: 'const wchar_t *irr::io::IIrrXMLReader<char_type,super_class>::getAttributeValue(int) const' : cannot convert parameter 1 from 'const char [5]' to 'int'
1>        with
1>        [
1>            char_type=wchar_t,
1>            super_class=irr::IReferenceCounted
1>        ]
1>        There is no context in which this conversion is possible
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(64) : error C2664: 'const wchar_t *irr::io::IIrrXMLReader<char_type,super_class>::getAttributeValue(int) const' : cannot convert parameter 1 from 'const char [5]' to 'int'
1>        with
1>        [
1>            char_type=wchar_t,
1>            super_class=irr::IReferenceCounted
1>        ]
1>        There is no context in which this conversion is possible
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(65) : error C2664: 'int irr::io::IIrrXMLReader<char_type,super_class>::getAttributeValueAsInt(const char_type *) const' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
1>        with
1>        [
1>            char_type=wchar_t,
1>            super_class=irr::IReferenceCounted
1>        ]
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(74) : error C2440: '=' : cannot convert from 'const wchar_t *' to 'const char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(83) : error C2664: 'strcmp' : cannot convert parameter 2 from 'const wchar_t *' to 'const char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\dokumente\programmierung\c++\irraor\irraor\ixml.h(83) : fatal error C1903: unable to recover from previous error(s); stopping compilation
I know its an include problem (already checked for cross includes, but there aren't any), cause the implementation of the IXML class is 100% correct... i didn't got these cast errors yesterday and all I added since then was the ISimulationManager Main Class... before that i used the ICore as "app-entry-point"....

heres a short cut-out of the IXML.h :

Code: Select all

#include "ISimulation.h"

struct node_tupel
{
	const char* name;
	EXML_NODE type;
};


class IXML
{
	private:
		IrrlichtDevice* device;
		IFileSystem* fs;
		IXMLReader* xml;
		ISimulation* simData;

		u32 step_nr;
		node_tupel node;

	public:
		IXML(IrrlichtDevice* dev, ISimulation* simulation);
		~IXML() {};

		ISimulation* read_XML(c8* xml_file, IrrlichtDevice* device);

	private:
		Property get_AttributeSlot();
		ElementHead get_ElementHead();
		node_tupel get_Node();

		void read_SimulationParameters();

		void read_SingleObject();
		void read_SingleAgent();
		void read_SingleStep();

		void read_Objects();
		void read_Agents();
		void read_Steps();
};

IXML::IXML(IrrlichtDevice* dev, ISimulation* simulation) 
	: step_nr(0), device(dev), simData(simulation)
{ 
	fs = device->getFileSystem();	// getting pointer to the IFileSystem 
};

Property IXML::get_AttributeSlot()
{
	Property p;

	p.name = xml->getAttributeValue(0);
	p.value = xml->getAttributeValue(1);

	return p;
};

ElementHead IXML::get_ElementHead()
{
	ElementHead head;

	head.name = xml->getAttributeValue("name");
	head.type = xml->getAttributeValue("type");
	head.id = xml->getAttributeValueAsInt("id");

	return head;
};

node_tupel IXML::get_Node()
{
	node_tupel n;

	n.name = xml->getNodeName();
	n.type = xml->getNodeType();

	return n;
};

void IXML::read_SimulationParameters()
{
	// read forward till Parameters Node reached
	while (strcmp("SimulationParameters", xml->getNodeName())) xml->read();
				
	while (xml && xml->read()) 
	{
		if (!strcmp("Slot", xml->getNodeName())) 
			simData->insert_Parameter(get_AttributeSlot());

		if (!strcmp("SimulationParameters", xml->getNodeName()) && xml->getNodeType() == EXN_ELEMENT_END) break;
	}
};
etc....

uah, hope someone gets what i wanted to say...

manyyyy thx in advance

greets
paddy
[/code]
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi, paddy.

Have you tried using "Rebuild ALL" instead of "compile"?

You don't seem to have compiler directives for your includes.

Also you compiler is returning this:
cannot convert parameter 1 from 'const char [5]' to 'int'
getAttributeValue(int) is expecting an integer as input and your sending a string.

I think it's there:

Code: Select all

ElementHead IXML::get_ElementHead() 
{ 
   ElementHead head; 

   head.name = xml->getAttributeValue("name"); 
   head.type = xml->getAttributeValue("type"); 
   head.id = xml->getAttributeValueAsInt("id"); 

   return head; 
}; 
Have your tried doing this?: (Why the use of the ""?)

Code: Select all

ElementHead IXML::get_ElementHead() 
{ 
   ElementHead head; 

   head.name = xml->getAttributeValue(name); 
   head.type = xml->getAttributeValue(type); 
   head.id = xml->getAttributeValueAsInt(id); 

   return head; 
}; 
paddy
Posts: 25
Joined: Tue Oct 23, 2007 12:30 pm

Post by paddy »

christianclavet wrote:Hi, paddy.

Have you tried using "Rebuild ALL" instead of "compile"?
yes, it also doesnt work
You don't seem to have compiler directives for your includes.
as i tried to get rid of this problem i took out my
"double include checks"

usually, every .h file has the directives :

Code: Select all

#ifndef I_<name>_H
#define I_<name>_H

...

#endif
but it doesn't matter if i use them or not. the problem
is there anyway :(
I think it's there:

Code: Select all

ElementHead IXML::get_ElementHead() 

   head.name = xml->getAttributeValue("name"); 
Have your tried doing this?: (Why the use of the ""?)

Code: Select all

ElementHead IXML::get_ElementHead() 
{ 
   ElementHead head; 

   head.name = xml->getAttributeValue(name); 
   head.type = xml->getAttributeValue(type); 
   head.id = xml->getAttributeValueAsInt(id); 

   return head; 
}; 
that wouldnt make sense in my case... xml->getAttributeValue("name") gets the value of the
first field in the current node of my xml file. the field is called "name" ... therefore i used it the way i wrote above...

getAttributeValue() has 2 overrides, one for int's and one for a string...

as i said, the code in there is 100% correct, cause yesterday it runned fine, it is a really weird problem that
drives me crazy :-(



[/quote]
paddy
Posts: 25
Joined: Tue Oct 23, 2007 12:30 pm

Post by paddy »

omg, i found it.... today in the morning i changed my IXML class
from IrrXML to IXML using auto replace...

what I didn't noticed, the IDE replaced also the line :

Code: Select all

IrrXMLReader* xml; 

to 

IXMLReader* xml;
and there is also a IXMLReader class in the Irrlicht Engine,
which appearently uses slight different functions... (which caused the cast errors O_O)

puhhh, it took hours !! but now all is fine like before...
anyway, this was my dumbness ;-)

topic closed now :)
thx anyway :)
Post Reply