Solved

HELP!!!: Passing collection objects???

Posted on 1998-10-24
2
191 Views
Last Modified: 2013-11-20
How to pass collection classes as argument for template & non-template type???

I've tried both but failed..... quite frustrating...

In my code,

CStringArray aString;
CArray <CString, LPCSTR> str;
CMyClass obj;

obj.method(aString, str);

=======
void CMyClass::
      method(CStringArray aStr, CArray<CString, LPCSTR> str)
{
   ......
}

Then I got this error

C2664: cannot convert parameter 1 from 'class CStringArray' to 'class CStringArray'

======
Pls show me the right way.... Thanks......
0
Comment
Question by:samyee
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1323788
CStringArray & CArray can not be copied.  The "method" member functon when called attempts to generate a copy into the local variables used by the procedure.

(1) Use a reference or pointer to the type in the function declaration, to avoid copying, OR (2) derive a class from CArray/CStringArray which includes copying functionality.

A reference would look like this:

     void CMyClass::
           method(CStringArray& aStr, CArray<CString, LPCSTR>& str)
     {
        ......
     }


note the ampersands

Remember method is working with with the original variable now (under a "pseudo name").  If "method" is not supposed to be able to change the array variables, add const to one or both array parameters :

     void CMyClass::
           method( const CStringArray& aStr, const CArray<CString, LPCSTR>& str)
     {
        ......
     }



0
 

Author Comment

by:samyee
ID: 1323789
Thanks... it's work :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 68
Expand to include initial dialog with two choices. 9 67
lucky13 challenge 11 120
ShiftLeft challenge 21 76
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now