cant use string class

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
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

cant use string class

Post by blayde »

this is wierd. i've never seen somthing like this before. if i compile the following class i get a message that i'm using "string" as a class, but it isn't defined as a class.

if i take out the irr' 'include' and 'usings' it compiles fine. cant find anything on google. anyone know what is going on ?

Code: Select all

#include "irrlicht.h"
#include "vector3d.h"
#include <string>
//#include <iostream>


using namespace irr;
using namespace core;
using namespace std;

class PlayerData
{
	private:
	string mdlLoc;
	string texLoc;
	//vector3df position;
 	//vector3df rotation;
 	public:
 	void test(){};
};
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

You include string from STL, but Irrlicht has also it's own string class. So how compilator can guess which one you want to use. Try following (if STL string is what you want):

Code: Select all

#include "irrlicht.h" 
#include "vector3d.h" 
#include <string> 
//#include <iostream> 


using namespace irr; 
using namespace core; 

class PlayerData 
{ 
   private: 
   std::string mdlLoc; 
   std::string texLoc; 
   //vector3df position; 
    //vector3df rotation; 
    public: 
    void test(){}; 
}; 
Tomasz Nowakowski
Openoko - www.openoko.pl
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

Post by blayde »

ahh, ok.

thanks a lot.

hmm, is there any way around that ?
doing std::string all the time is going to be annoying and messy.
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

You can don't use "using namespace core;" but then you will have to use "core::" before all the stuff from this namespace. Or you can stop using STL string, and use Irrlicht one ;)

But i strongly suggest to familiarize with namespaces. It might be annoying adn messy in the begining but later you will understand how helpful they are.
Tomasz Nowakowski
Openoko - www.openoko.pl
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

Post by blayde »

yeah, i understand namespaces. just never seen this prob before. and i was hoping there was a way to tell the compiler "assume i'm using namespace 'std'"

thanks
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

"using namespace std" is exacly "assume i'm using namespace 'std'" :)
But you also told compiler to asume that you are using irr and core namespace ;).
Tomasz Nowakowski
Openoko - www.openoko.pl
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

Post by blayde »

sorry, buggered that up, i meant i wanted to tell it that in the case of a collision of multiple difinitions i wanted it to assume i was reffering to 'std'
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

You could do a define statement at the top of your code so that you do not have to type stl::string everytime like this but I mean you are still just saving three letters. I guess that could add up a lot of time if you have trouble typeing "::"

Code: Select all

#define string2 stl::string
:D
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

Post by blayde »

yeah, though about it. thought about changed irr's string class name too. i'll see once i start to use this code for reall.

i'll probably do the latter, i think that's how it should be in the first place anyhow.
Post Reply