Server Help

Bot Questions - STL components in VC++ 6.0

tansey - Tue Dec 21, 2004 5:26 am
Post subject: STL components in VC++ 6.0
I'm trying to use a couple of simple container classes in my bot ( a map and a set) and VC++ 6.0 doesn't want to let the thing compile.

I've got a separate header and cpp file for my actual core. So I'm trying to make my bot have 2 fields, one map and one set, and I'm declaring them as such:

Code: Show/Hide
   set<int>               set1;      
   map <Player*, int>         map1;               



I'm constantly getting errors like:
Quote:
c:\program files\continuum\mervbot\src\r2g2\dt.h(104) : error C2143: syntax error : missing ';' before '<'
c:\program files\continuum\mervbot\src\r2g2\dt.h(104) : error C2501: 'set' : missing storage-class or type specifiers
c:\program files\continuum\mervbot\src\r2g2\dt.h(104) : error C2059: syntax error : '<'
c:\program files\continuum\mervbot\src\r2g2\dt.h(104) : error C2238: unexpected token(s) preceding ';'


Not sure what's going on here. Any help would be appreciated.
Cyan~Fire - Tue Dec 21, 2004 1:07 pm
Post subject:
Make sure you have the line "using namespace std;" at the top of every file that uses STL classes.

Also make sure you don't ever use STL classes because they're the worst thing to debug in ages.
tansey - Tue Dec 21, 2004 1:25 pm
Post subject:
Yep, tried that...
When i did using namespace std but it said:
Quote:
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(15) : error C2871: 'std' : does not exist or is not a namespace

Underlord - Tue Dec 21, 2004 2:21 pm
Post subject:
Quote:
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(15) : error C2871: 'std' : does not exist or is not a namespace


Most likely cause for that is .... you put "using namespace std;" under a traditional header file ".h".

Code: Show/Hide

#include <fstream>
using namespace std;

right

#include <fstream.h>
using namespace std;

wrong


If you setup a namespace where you declare map/set, then u can access them elsewhere after includes with
" what_you_called_your_namespace::set <int> setl; "
tansey - Tue Dec 21, 2004 3:41 pm
Post subject:
Thanks so far! But now it's giving me more errors:

Quote:
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(144) : warning C4786: 'std::pair<std::_Tree<int,int,std::set<int,std::less<int>,std::allocator<int> >::_Kfn,std::less<int>,std::allocator<int> >::const_iterator,std::_Tree<int,int,std::set<int
,std::less<int>,std::allocator<int> >::_Kfn,std::less<int>,std::allocator<int> >::const_iterator>' : identifier was truncated to '255' characters in the debug information
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(144) : warning C4786: 'std::reverse_bidirectional_iterator<std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Pla
yer *>,std::allocator<int> >::iterator,std::pair<Player * const,int>,std::pair<Player * const,int> &,std::pair<Player * const,int> *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(144) : warning C4786: 'std::reverse_bidirectional_iterator<std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Pla
yer *>,std::allocator<int> >::const_iterator,std::pair<Player * const,int>,std::pair<Player * const,int> const &,std::pair<Player * const,int> const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(144) : warning C4786: 'std::pair<std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Player *>,std::allocator<int>
>::iterator,std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Player *>,std::allocator<int> >::iterator>' : identifier was truncated to '255' characters in the debug in
formation
c:\program files\continuum\mervbot\src\hostbot\hostbot.h(144) : warning C4786: 'std::pair<std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Player *>,std::allocator<int>
>::const_iterator,std::_Tree<Player *,std::pair<Player * const,int>,std::map<Player *,int,std::less<Player *>,std::allocator<int> >::_Kfn,std::less<Player *>,std::allocator<int> >::const_iterator>' : identifier was truncated to '255' characters in
the debug information


Also, it's having trouble with the String class being recognized:

Quote:
c:\program files\continuum\mervbot\src\hostbot\spawn.h(242) : error C2664: 'void __thiscall botInfo::sendPublic(char *)' : cannot convert parameter 1 from 'class String' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

tansey - Tue Dec 21, 2004 5:43 pm
Post subject:
Okay, I figured out the issues with the map, but my String issues are still there. For some reason, it's not acknowledging the operator overloaders or the copy constructors or anything like that.

Is it maybe because of my namespace std; declaration, since String is a class not in that namespace?
Mr Ekted - Tue Dec 21, 2004 5:54 pm
Post subject:
Knitting is a fun hobby I hear.
Cyan~Fire - Tue Dec 21, 2004 6:01 pm
Post subject:
Make sure "#define STRING_CAST_CHAR" is at the top of spawn.h.
tansey - Tue Dec 21, 2004 6:44 pm
Post subject:
Yep, it is.

The top of my bot's .h file (separate file, not spawn.h):

Code: Show/Hide

#ifndef HOSTBOT_H
#define HOSTBOT_H

#include "..\dllcore.h"
#include <map>
#include <set>
#include <iostream>
using namespace std;

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

D1st0rt - Tue Dec 21, 2004 7:41 pm
Post subject:
ouch Ekted, lol

do you not like the STL?
CypherJF - Tue Dec 21, 2004 8:08 pm
Post subject:
Ekted is old skewl... icon_wink.gif He's too good for STL icon_smile.gif... lol.
D1st0rt - Tue Dec 21, 2004 8:18 pm
Post subject:
maybe some day I will level up into a Mr Ekted
tansey - Tue Dec 21, 2004 8:28 pm
Post subject:
um....is there any other library you guys would reccommend to use that has both a map and a set class? I know stl has a lot of memory leaks, but it's all I know! icon_sad.gif
Cyan~Fire - Tue Dec 21, 2004 11:02 pm
Post subject:
I don't see it at the top of that file. And it should be in the spawn.h.

As far as STL goes, you'll learn a lot about the language if you do it yourself. That's what I did, and man, do I feel in control of my program. icon_razz.gif

And, of course, you can always re-use a template class once you've made one.
Mr Ekted - Wed Dec 22, 2004 1:15 am
Post subject:
D1st0rt wrote:
ouch Ekted, lol

do you not like the STL?


I dislike all wrappers for common stuff. They always add inefficiency, and even if they are bug-free, they are often mis-used by interface or mis-used by the incorrect choice of aggregate type. IMO, you learn how things work and how to implement them, or you do something else.

When I see code like this, it makes me want to puke:

Code: Show/Hide
String Function (String a, String b)
{
return a + " - " + b;
}


Do you have any idea how bad this code is? I believe this would perform four memory allocations, instead of an acceptible zero.
tansey - Wed Dec 22, 2004 5:17 am
Post subject:
I've written all these classes on my own before too, for my CS classes...but I would tend to think that a guy who's only got 7 months c++ experience wouldn't make as efficient a map/set class as the stl writers (HP?)
Cyan~Fire - Wed Dec 22, 2004 10:51 am
Post subject:
Oh, they might not be efficient, but you can always improve them in the future. The ease of debugging makes up for any slight efficiency loss.
Mr Ekted - Wed Dec 22, 2004 11:33 am
Post subject:
No matter how efficient the String class is, you can write the code above that runs 10-20x faster, and it's MUCH easier to debug.
Dr Brain - Wed Dec 22, 2004 11:38 am
Post subject:
You can't perform less than two allocations for that functions task.

I agree that having that code inline would be much easier to debug, though.
Cyan~Fire - Wed Dec 22, 2004 12:49 pm
Post subject:
You could only perform one allocation if the class was designed properly.

And my talking about efficiency was mainly targeted towards var-length arrays, trees, etc.
Bak - Wed Dec 22, 2004 6:01 pm
Post subject:
STL doesn't have memory leaks, where did you hear that?

the String class is not STL's class... it's written by catid
CypherJF - Wed Dec 22, 2004 6:45 pm
Post subject:
I wrote a string class once.
Cyan~Fire - Wed Dec 22, 2004 11:42 pm
Post subject:
OMFG I DID TOO OMG OMG OMG WHAT'S YOUR #??
D1st0rt - Thu Dec 23, 2004 11:41 am
Post subject:
I wrote a string class never.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group