|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
|
[C++] Copy constructor ?
Ho una classe LLMessage che è un gestore di messaggi e i messaggi sono contenuti in una std::list.
Codice:
class LLMessage
{
public:
LLMessage() { Rewind(); }
bool GetNext (LLMsgVals& vals)
{
while ( m_ListIter != m_MsgVals.end() )
{
if ( (*m_ListIter).Delay == 0 || ((*m_ListIter).Delay > 0 && (*m_ListIter).ExpireTime <= time(NULL)) )
{
vals = *m_ListIter;
m_ListIter = m_MsgVals.erase(m_ListIter);
return true;
}
++m_ListIter;
}
m_ListIter = m_MsgVals.begin();
return false;
}
...
private:
list <LLMsgVals> m_MsgVals;
}
GetNext è una funzione che estrae un messaggio dalla lista, quindi lo elimina. Adesso ho un problema: siccome devo usare questa lista anche da un altro processo (un autotester), prima di usarla la passo alla classe AutoTester come riferimento Codice:
AutoTesterSpace::AT_RESULT AT_Res = m_AutoTest->Process( msgIn, m_msgTrolley, matrix, time(NULL) ); Codice:
AT_RESULT AutoTester::Process(LLCMessage& InMsg, LLMessage& OutMsg, ConnectionMatrix_t& matrix, int TransactionID)
{
m_OutMsg = OutMsg; // create a copy as the passed msg CANNOT BE CHANGED !!!
...
}
Ho provato ad aggiungere un copy constructor: Codice:
LLMessage(const LLMessage& msg) : m_MsgVals(msg.m_MsgVals) { Rewind(); }
Non so se ho spiegato bene ... qualcuno mi sa aiutare ? Grazie.
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z ∞Mb - Win Eight SP (1 > yours) 16 Valve |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
|
Cosa li apro a fare i 3d se poi risolvo da solo ?
Ho trovato il baco: Codice:
AT_RESULT AutoTester::Process(LLCMessage& InMsg, LLMessage& OutMsg, ConnectionMatrix_t& matrix, int TransactionID)
{
m_OutMsg = OutMsg; // create a copy as the passed msg CANNOT BE CHANGED !!!
...
HandleMessageOut( OutMsg, SqlMatrixId, TransactionID );
...
}
![]() Vabbè, grazie lo stesso, come non detto
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z ∞Mb - Win Eight SP (1 > yours) 16 Valve |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Se mettevi const al parametro te ne accorgevi
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
|
in effetti
Ma tanto cambio il sistema, l'AutoTester non deve essere costretto a fare una copia perchè non deve sapere che non può toccare l'originale. Ci deve pensare chi usa l'AutoTester. Però hai ragione, non uso spesso i const
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z ∞Mb - Win Eight SP (1 > yours) 16 Valve |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:36.





















