2012-08-28 32 views
0

我全局定義:調整大小矢量編譯器錯誤

vector<player> cUser; 

玩家結構是這樣:

struct player 
{ 
char buffer[256]; 
string username; 
string password; 
string version; 
int playerID; 
int X; 
int Y; 
int direction; 
string chats[5]; 
unsigned long robotID[3]; 
int gender; 
int securityLevel; 
float rep; 
int isMember; 
int inBattle; 
int isFollowed; 
int playerLocked; 
string currentMap; 
string lastHavenMap; 
int mapHeight; 
int mapWidth; 
unsigned long money; 
unsigned long points; 
int wins; 
int losses; 
string oldIP; 
string newIP; 
unsigned long lastOnline; 
int layer; 
int rank; 
int kicked; 
void logout(); 
void refresh(); 
//other 
void startLoops(); 
int execLoops; 
//for the robots 
Robots Robot[3]; 
int robotOut; 
int totalRobots; 
void addExp(int, int); 
void subExp(int, int); 
int calcRobotExp(int); 
//battles 
player *enemyBattleUser;//enemy is a player 
npc enemyBattleNpc;//enemy is an npc or boss 
Robots rogueRobot;//enemy is a rogue robot 
string mainBattleUser; 
int battleChoice;//which choice of the battleChoiceType 
int battleChoiceType;//0 attack, 1 team, 2 flee 
int battleSAD;//short for battleSceneAlgorythmsDone 
int battleType;//0-rogue, 1=npc, 2-boss 3-player 
int subHealth(int, int, int); 
void addHealth(int, int, int); 
void battleStart(string, int, int); 
void battleEnd(int); 
void getMove(); 
void userTurn(int&, int&, int&, string&, string&, int&); 
void enemyTurn(int&, int&, int&, string&, string&, int&); 
void extraDamage(int&, string&, string&, int); 
void battleScene(); 
//sockets 
int sockID;//main socket id 
int cSockID;//chat socket id 
void userSockError(); 
//roam 
int rogueBattleCalc(); 
void warp(string, int, int); 
int checkNpcBattle(); 
void sendInitData(); 
void roamWorld(); 
int playerWalk(int); 
//chatting 
void chatLoop(); 
void executeCommand(string); 
int lastMessageSeen[5]; 
string chatName[5]; 
int chatsOpen; 
//threads 
boost::thread mainThread; 
boost::thread chatThread; 
}; 

然後當我嘗試通過以下任何一種來調整它,它給了我一個非常大的錯誤,我相信是告訴我做一個構造函數/析構函數,當我這樣做時,仍然給我同樣的錯誤。

cUser.resize(cUser.size()+1); 

player tempUser; 
//members of tempUser set here 
cUser.push_back(tempUser); 

cUser.erase(index); 

但是,當我以同樣的方式調整這個結構,它工作得很好,它仍然沒有構造函數/析構函數,並且它以同樣的方式定義旁邊cUser。

struct chatbox 
{ 
     //chatbox structure 
     string name; 
     int locked;//0 no, 1 yes 
     int staffOnly;//0 no, 1 yes 
     int mType[5]; 
     int security[5]; 
     string username[5]; 
     string message[5];//the higher the index the newer the message 
     int messagesNo; 
}; 

任何幫助,將不勝感激,謝謝。

錯誤:

$ make 
g++ -c -o server.o server.cpp 
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/i686-pc-cygw 
in/bits/c++allocator.h:34:0, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/allocat 
or.h:48, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/string:43, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/locale_ 
classes.h:42, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/ios_bas 
e.h:43, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ios:43, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/istream:40, 
       from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/fstream:40, 
       from server.cpp:5: 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ext/new_allocator.h: In member fun 
ction `void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp 
= player, _Tp* = player*]': 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_vector.h:745:6: instant 
iated from `void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _T 
p = player, _Alloc = std::allocator<player>, value_type = player]' 
server.cpp:373:32: instantiated from here 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ext/new_allocator.h:105:9: error: 
no matching function for call to `player::player(const player&)' 
user.hpp:81:1: note: candidates are: player::player() 
user.hpp:81:1: note:     player::player(player&) 
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/vector:69:0, 

       from server.cpp:10: 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/vector.tcc: In member functio 
n `void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterat 
or, const _Tp&) [with _Tp = player, _Alloc = std::allocator<player>, std::vector 
<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<player*, std::vector<play 
er> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = player 
*]': 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_vector.h:749:4: instant 
iated from `void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _T 
p = player, _Alloc = std::allocator<player>, value_type = player]' 
server.cpp:373:32: instantiated from here 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/vector.tcc:306:19: error: no 
matching function for call to `player::player(const player&)' 
user.hpp:81:1: note: candidates are: player::player() 
user.hpp:81:1: note:     player::player(player&) 
In file included from server.hpp:9:0, 
       from server.cpp:15: 
/usr/include/boost/thread/detail/thread.hpp: In member function `player& player: 
:operator=(player&)': 
user.hpp:81:1: instantiated from `void std::vector<_Tp, _Alloc>::_M_insert_aux 
(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = player, _Alloc = st 
d::allocator<player>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_i 
terator<player*, std::vector<player> >, typename std::_Vector_base<_Tp, _Alloc>: 
:_Tp_alloc_type::pointer = player*]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_vector.h:749:4: instant 
iated from `void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _T 
p = player, _Alloc = std::allocator<player>, value_type = player]' 
server.cpp:373:32: instantiated from here 
/usr/include/boost/thread/detail/thread.hpp:114:17: error: `boost::thread& boost 
::thread::operator=(boost::thread&)' is private 
user.hpp:81:1: error: within this context 
/usr/include/boost/thread/detail/thread.hpp:114:17: error: `boost::thread& boost 
::thread::operator=(boost::thread&)' is private 
user.hpp:81:1: error: within this context 
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/vector:69:0, 

       from server.cpp:10: 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/vector.tcc: In member functio 
n `void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterat 
or, const _Tp&) [with _Tp = player, _Alloc = std::allocator<player>, std::vector 
<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<player*, std::vector<play 
er> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = player 
*]': 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/vector.tcc:312:4: note: synth 
esized method `player& player::operator=(player&)' first required here 
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/vector:63:0, 

       from server.cpp:10: 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_construct.h: In function 
`void std::_Construct(_T1*, const _T2&) [with _T1 = player, _T2 = player]': 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_uninitialized.h:74:3: i 
nstantiated from `static _ForwardIterator std::__uninitialized_copy<<anonymous> 
>::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _I 
nputIterator = player*, _ForwardIterator = player*, bool <anonymous> = false]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_uninitialized.h:116:46: 
instantiated from `_ForwardIterator std::uninitialized_copy(_InputIterator, _In 
putIterator, _ForwardIterator) [with _InputIterator = player*, _ForwardIterator 
= player*]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_uninitialized.h:318:63: 
instantiated from `_ForwardIterator std::__uninitialized_copy_a(_InputIterator, 
_InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = 
player*, _ForwardIterator = player*, _Tp = player]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_uninitialized.h:328:24: 
instantiated from `_ForwardIterator std::__uninitialized_move_a(_InputIterator, 
_InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = player*, 
_ForwardIterator = player*, _Allocator = std::allocator<player>]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/vector.tcc:338:8: instantia 
ted from `void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>: 
:iterator, const _Tp&) [with _Tp = player, _Alloc = std::allocator<player>, std: 
:vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<player*, std::vect 
or<player> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = 
player*]' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_vector.h:749:4: instant 
iated from `void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _T 
p = player, _Alloc = std::allocator<player>, value_type = player]' 
server.cpp:373:32: instantiated from here 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_construct.h:80:7: error: 
no matching function for call to `player::player(const player&)' 
user.hpp:81:1: note: candidates are: player::player() 
user.hpp:81:1: note:     player::player(player&) 
<builtin>: recipe for target `server.o' failed 
make: *** [server.o] Error 1 
+4

我猜錯誤是因爲'boost :: thread'不可複製。你真的想爲每個球員提供兩個線程嗎? –

+0

是的,不幸的是,他們是需要的,生病了,看看 – user1630850

+0

是的謝謝,這是問題! – user1630850

回答

4

一個可能的問題是,你的player類有boost::thread數據成員,而這些都是不可拷貝或轉讓。由於vector::resize()可能需要複製和/或分配,因此編譯失敗。

+0

是的,這是問題,謝謝。 – user1630850