Solved

HELP!!!: Passing collection objects???

Posted on 1998-10-24
2
179 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
Comment Utility
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
Comment Utility
Thanks... it's work :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 113
sum28 challenge 31 95
only14 challenge 19 63
abstract class with all non abstract mentods 6 71
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

11 Experts available now in Live!

Get 1:1 Help Now