Thread: Const question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654

    Const question

    I just wanted to hear opinions on this.
    There's a function that takes a pointer...
    Code:
    ERROR1 CRegistry::AddIndex(const CIndex* const pIndex, UINT* const pVectorIndex, const bool bLoadingNow)
    ...which it promises that it will in no way change or mess with.
    However, the problem comes later:
    Code:
    vector<CIndex*> m_vIndexes; // Here is where all the indexes are stored
    CTypedPtrMap<CMapWordToPtr, UINT64, CIndex*> m_IndexByID; // Used to find an index by its ID
    
    rHive.m_vIndexes.push_back(pIndex);
    rHive.m_IndexByID.SetAt(pIndex->dwId, pIndex); // Save index in the list to identify it by its ID
    The function needs to save the pIndex is a vector for storage and set it in a map for lookup. Other functions will (and must) be able to modify these pointers, but the function itself will not mess around with pIndex.

    So the question is: should it be feasible to cast away the const before storing it in the map? That way the function can take a const-type pointer, which be const correct since the function won't modify the pointer.
    Last edited by Elysia; 12-01-2007 at 08:18 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Need help implementing a class
    By jk1998 in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2007, 03:13 PM
  5. Replies: 6
    Last Post: 12-06-2005, 09:23 AM