RE: [Dev-C++] 'extern const' and std::vector
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-05-01 18:20:34
|
Since the rooms are one next the other then you do not need random access
(=after room [1] you may access room [2679]). If you do not need such jumps
then a tree or a list or whatever may be ok too. std::list for example is
great for sorting.
Regarding the vector you can use one in a namespace and access it with an
iterator for parts which can write and const_iterator for the parts who can
only read.
The iterators of vector arre random access iterators, so they entirely
behave as regular pointers. Code that demonstrates vector iterator ability:
#include <vector>
#include <iostream>
namespace hesperia
{
std::vector<int>myvec(200);
}
int main()
{
using namespace std;
using hesperia::myvec;
vector<int>::iterator p=myvec.begin();
for(vector<int>::size_type i=0; i<myvec.size()/2; i++)
p[i]=7;
vector<int>::const_iterator r=myvec.begin();
for(vector<int>::size_type i=0; i<myvec.size()/2; i++)
cout<<r[i]<<" ";
*(p+7)=8;
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
-----Original Message-----
From: David McKen [mailto:ci...@ya...]
Sent: Thursday, May 01, 2003 8:54 PM
To: Ioannis Vranos
Subject: Re: [Dev-C++] 'extern const' and std::vector
Random access is essential!!!!
We are storing them sequentially and the system for access uses the fact
that room #3001 is located just after room #3000 (helps with speed).
Concerning the comment that this is a bad design. This vector is what needs
to be global. Only ceartain players (the admins) have the ability to
directly edit this room data (this will also be controlled). No matter what
part of the MMORPG is being used it will need access to this information
(only some basic information commands don't).
|