Solved

HELP!!!: Passing collection objects???

Posted on 1998-10-24
2
211 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
either24  challenge 19 101
wait notify demo infinite loop 3 121
pre4 challenge 19 103
Excel file not created as expected 7 79
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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

789 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