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
Solved

CArray of CArray

Posted on 2001-08-17
17
462 Views
Last Modified: 2013-11-20
Hi all,
    I'm trying to make a CArray of CArrays

CArray <CArray<long, long>, CArray<long, long> > testaArray;

But it does'nt work... always these errors:

error C2146: syntax error : missing ',' before identifier 'test'
C:\Tomoview 1.4R8\TVM\DovetailAutomaticAnalysis\DovetailAutomaticAnalysisDlg.cpp(3160) : error C2065: 'test' : undeclared identifier
C:\Tomoview 1.4R8\TVM\DovetailAutomaticAnalysis\DovetailAutomaticAnalysisDlg.cpp(3160) : error C2143: syntax error : missing '>' before ';'

Can someone help?...thanks
0
Comment
Question by:David MacDonald
  • 4
  • 4
  • 4
  • +2
17 Comments
 
LVL 1

Expert Comment

by:tvanceplus
ID: 6397546
I would use a CArray of pointers to CArray like this

CArray<CArray<long,long>*,CArray<long,long>*&> testaArray;

then just allocate the memory yourself.
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 6397573
Ok, that's cool, but why a CArray of CArray (not pointers) is not working?...


Also, why is it that when we pass a CArray as a function parameter, we have to write CArray<something, something>& ...

It's the '&' i'm wondering about...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6397863
That's strange - your code is compiling fine here:

#include <afxtempl.h>

CArray <CArray<long, long>, CArray<long, long> > testaArray;


typedef CArray<long,long> CLongArray;
typedef CArray<CLongArray, CLongArray> CLAA;

CLAA aa;

Did you forget '#include <afxtempl.h>'?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 1

Author Comment

by:David MacDonald
ID: 6397922
i'll try that out.... but I can declare a simple CArray with no trouble...

I'll be back on that...
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 6397951
OK, now i am confused.... I just retried it... and it works ok......................

dunno why...  since my problem is no more, here is a quiz, a answer I wonder about for a time now....

why is it that when we pass a CArray as a function parameter, we have to write CArray<something,
something>& ...

It's the '&' i'm wondering about...


Thanks for all the support in my "mysterious problem..."
0
 
LVL 86

Accepted Solution

by:
jkr earned 75 total points
ID: 6397994
>>we have to write CArray<something, something>& ...

That's because if you wrote 'CArray<something, something>', 'template class CArray< class _A, class _T>' would need to have a copy constructor defined (which it hasn't - there's no 'CArray< class _A, class _T>( const CArray< class _A, class _T>&)' ctor, and no 'operator=()', which would be necessary also), as you'd pass a copy of the (*WHOLE*) array to the called function - the appended '&' passes a reference to an array, and that's syntactically possible (and reasonable aso :o)
0
 
LVL 86

Expert Comment

by:jkr
ID: 6398413
>>It's the '&' i'm wondering about...

Still wondering? :o)
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6399984
the "&" says you pass a reference to an object of  CArray<T1,T2> type.

Pass by reference: a reference to the object (actually, a pointer) is passed to the function. the function can manipulate the original object.

Pass by value: a copy of the object is made on stack. The function uses it's own opy of the object (can't modify the original). For larger objects, this also tends to be ineffective (due to copying the entire object rather than a pointer, and perhaps complex constructors to be called.)

need an example?

b) already answered, but: CTemplate<x> is treated as completely different class than CTemplate<y>. i.a.W. the full type name is "CTemplate<>". "CTemplate" alone is no known type.

c) guess for youroriginal problem: did you accidently forget the space beetween the two closing '>' ? btw. the error message itself loks more like you didn't #include <afxtempl.h>.

good luck
Peter


0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6400552
this doesn't compile

     CArray< CArray< long, long>, CArray< long, long>> x;


this does

     CArray< CArray< long, long>, CArray< long, long> > x;

spot the difference yup it is the >> at the end - as you know >> is an operator and that is what the compiler is seeing first rather then the end of two templates


0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6400566
oops looks like peterchen answered the first reason - teach me to get interrupted
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6400679
hehe.. ths time not me ;)
0
 
LVL 86

Expert Comment

by:jkr
ID: 6401077
Hmm, if the Q is the original code, it is '> >'
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6403123
> Hmm, if the Q is the original code, it is '> >'

maybe - but when I did >> instead of > > I got the same error messages
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6403703
might be the space was inserted by the code police template task force, which might also explain "it suddenly works".
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6404230
> might be the space was inserted by the code police
> template task force, which might also explain "it
> suddenly works".

ah another believer of the code pixies
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 6407118
Don`t laugh about code pixies, or they will get pissed off!! :)

Thanks a lot folks, jkr gave me the explanation I sought.... thanks...

And don`t forget: beware the code pixies.... lol

0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6407826
sure I believe in them... In fact I worked for them for almost two years.... yeah, I tell you: the excitment, the adventure.... but the paperwork was eating me up
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Define unique primary key 9 95
notReplace  challenge 53 142
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
fizzArray2 challenge 1 91
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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