i am a c programmer, 6 month old for c++.

i am trying to add some feature to a huge c++ base code !.

stuck at this funtion . ( function names/varibles names modified )

void MCE::AddM( int Cid, int Tid, int Rid)
TrInstEntry* pTrInstanceEntry = (TrInstanceEntry*)m_MappingList->find(Tid);

if ( pTrInstanceEntry == 0 )
if ( nRbId != UNKNOWN )
pTrInstanceEntry = new TrInstanceEntry( Cid, Tid, Rid);
pTrInstanceEntry = new TrInstanceEntry(Cid,Tid );


later in the code i see the find being called with different ids..
for eg : id is from a array of Cids, we call, the
m_mappingList->find( Cid1);
also i see, m_MappingList being called with Tid type...

i was thinking the id is a kind of key..i am not sure, how we can access the same database without indicating which key we are using ! Confused, help me...

6 Years
Discussion Span
Last Post by griswolf
  • Please remember to use the code button when you post code. It makes it so much easier, better for the people who will be willing to help you.

As to your question:

i am not sure, how we can access the same database without indicating which key we are using

In normal usage, m_mappingList is not a 'database' but a 'data structure' It is important to use words clearly and correctly when thinking about and describing your programs (to yourself or others).

It looks to me as if both Tid and Cid are int, based on the declaration MCE::addM(int Cid, int Tid, int Rid)

If you have fully and correctly transcribed the declarations of the two "find" methods, the compiler will either complain or overwrite one with the other, since they have the same signature. (See note). Maybe you have not transcribed them correctly? (I wonder if they have the names findT(int tid) and findC(int cid) or if the methods are from different classes??)

If your description is correct (it seems likely) then you should try to compile with the warning level set high and see what warnings you get.

Note: Though the methods you show are the same, neither is ideal: It is better when the method does not change data to declare methods 'const' like this: TrInstanceEntry *find(int cid) const

You surely find it useful in your programming career to be very very organized when you think about problems. Usually, when you are that well organized in your thoughts, you can easily write a well organized question. This one did not seem very well organized to me. Perhaps your level of frustration is showing...

Edited by pyTony: fixed formating

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.