Solved

HELP!!!: Passing collection objects???

Posted on 1998-10-24
2
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 87
maven archtype selection in eclipse 1 59
Hibernate methods 2 87
wordmultiple challenge 12 169
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

734 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