How to define operator = in CStringArray?

This is a discussion on How to define operator = in CStringArray? within the C++ Programming forums, part of the General Programming Boards category; I write this below function to return CStringArray. Code: CStringArray info; info = m_Proc.Getinfo(m_arrFileName, m_arrPassword); When I compile there are ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    How to define operator = in CStringArray?

    I write this below function to return CStringArray.


    Code:
    CStringArray info;
    info = m_Proc.Getinfo(m_arrFileName, m_arrPassword);

    When I compile there are error message show like these


    Code:
    error C2582: 'CStringArray' : 'operator =' function is unavailable
    error C2582: 'CStringArray' : 'operator =' function is unavailable
    error C2679: binary '+=' : no operator defined which takes a right-hand operand of type 'class CStringArray' (or there is no acceptable conversion)
    error C2558: class 'CStringArray' : no copy constructor available

    Do you know how to define operator = in CStringArray? Are there another way to do that?

    Thank you for your answer.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I notice that it doesnt have operator= according to MSDN...

    Your best bet is to use the member functions that CStringArray does provide;
    void InsertAt( int nIndex, CObject* newElement, int nCount = 1 );
    throw( CMemoryException );

    void InsertAt( int nStartIndex, CObArray* pNewArray );
    throw( CMemoryException );

    void SetAtGrow( int nIndex, CObject* newElement );
    throw( CMemoryException );

    int Add( CObject* newElement );
    throw( CMemoryException );
    I dont know what m_Proc is...but you may need to look at what's returned and apply it using une of the above

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    68
    Thank you for your answer Fordy. m_Proc is just only object.
    Now I can do that by using

    Code:
    CStringArray info;
    info.Copy(m_Proc.Getinfo(m_arrFileName, m_arrPassword);

    But I want to ask another question that I write Getinfo function to return CStringArray.

    Code:
    CStringArray CCrypt::Getinfo(const CStringArray& fileName, const CStringArray& password) 
    {
    CStringArray privkeyinfo;
    ..
    ..
    ..
    return privkeyinfo;
    }
    But when I compile there are error message show

    Code:
    error C2558: class 'CStringArray' : no copy constructor available
    Do you know how to solve my problem?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Sad state of affairs when M$ ships a container class with no copy constructor (I never noticed this before....that's real shoddy)......I prefer the STL these days.....

    Ok..well....I guess you could wrap it in another object for which you can define a copy constructor....or define privkeyinfo before the call and pass a reference allong with the other 2 references you are passing to CCrypt::Getinfo.....this last way would also be more efficient

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Fordy
    I notice that it doesnt have operator= according to MSDN...
    BAHAHAHAHAHAHAHAHA

    stupid microsoft numnuts.
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 06:33 AM
  2. Compiling error: Too many arguments.
    By Tuah in forum C++ Programming
    Replies: 16
    Last Post: 06-10-2008, 05:28 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21