Board index » Visual Studio » Nested CList

Nested CList

Visual Studio366
I'm constructing a grid of objects (squares as in a crossword puzzle). What

I would like to do is have a CList within a CList. Something like:



CList<Square, Square&>SquareList;

CList<SquareList, SquareList&>SquareGrid;



However, I get a syntax error on the second definition (syntax error: '>').

I guess I could break it down into two separate CList and correlate the two,

but I was hoping someone would know how define a nested CList.



Thanks in advance,


-
 

Re:Nested CList

"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

Quote
I'm constructing a grid of objects (squares as in a crossword puzzle).

What

I would like to do is have a CList within a CList. Something like:



CList<Square, Square&>SquareList;

CList<SquareList, SquareList&>SquareGrid;



However, I get a syntax error on the second definition (syntax error:

'>').

I guess I could break it down into two separate CList and correlate the

two,

but I was hoping someone would know how define a nested CList.



Thanks in advance,



This may not be the problem but have you tried using typedef?



typedef CList<Square, Square&>SquareList;

typedef CList<SquareList, SquareList&>SquareGrid;



What you have is declaring a variable of type CList<Square, Square&>, not an

assignable datatype. So the typedef should clear that up.



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.





-

Re:Nested CList

Well, the good news is that your solution fixed the compiler error and I can

actually AddTail to both CLists (SquareList and SquareGrid) to populate them.

However, the bad news is that I can only retrieve info (GetAt or FindIndex)

from SquareList (cast as Square), because it actually points to an object

(Square) not a typdef. Casting the results of accessing SquareGrid as a

CList or as a SquareList didnt' help, because both are typedefs. I think

we're close, but I just need to somehow get at the SquareGrid CList first,

before I can get the final answer from SquareList CList.



What do you think?



"Frank Hickman [MVP]" wrote:



Quote
"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

news:9F33D3FE-5235-40E6-865E-D27DEAF82C55@microsoft.com...

>I'm constructing a grid of objects (squares as in a crossword puzzle).

>What

>I would like to do is have a CList within a CList. Something like:

>

>CList<Square, Square&>SquareList;

>CList<SquareList, SquareList&>SquareGrid;

>

>However, I get a syntax error on the second definition (syntax error:

>'>').

>I guess I could break it down into two separate CList and correlate the

>two,

>but I was hoping someone would know how define a nested CList.

>

>Thanks in advance,



This may not be the problem but have you tried using typedef?



typedef CList<Square, Square&>SquareList;

typedef CList<SquareList, SquareList&>SquareGrid;



What you have is declaring a variable of type CList<Square, Square&>, not an

assignable datatype. So the typedef should clear that up.



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.







-

Re:Nested CList

"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

Quote
Well, the good news is that your solution fixed the compiler error and I

can

actually AddTail to both CLists (SquareList and SquareGrid) to populate

them.

However, the bad news is that I can only retrieve info (GetAt or

FindIndex)

from SquareList (cast as Square), because it actually points to an object

(Square) not a typdef. Casting the results of accessing SquareGrid as a

CList or as a SquareList didnt' help, because both are typedefs. I think

we're close, but I just need to somehow get at the SquareGrid CList first,

before I can get the final answer from SquareList CList.



What do you think?







How are you actually using them? Remember that using typedef does not

actually create an object so the two lines I suggested would still need to

be used in a declaration statement.



typedef CList<Square, Square&>SquareList;

typedef CList<SquareList, SquareList&>SquareGrid;



SquareGrid m_sq_grid;

Square sq(0,0,10,10);

SquareList sq_lst;

sq_lst.AddTail( sq );

m_sq_grid.AddTail( sq_lst );



// This should work as is, no casting should be needed...

POSITION pos= m_sq_grid.GetHeadPosition();

SquareList& sq_lst_ref= m_sq_grid.GetNext( pos );

POSITION posLst= sq_lst_ref.GetHeadPosition();

Square& sq_ref= sq_lst_ref.GetNext( pos );



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.





Quote
"Frank Hickman [MVP]" wrote:



>"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

>news:9F33D3FE-5235-40E6-865E-D27DEAF82C55@microsoft.com...

>>I'm constructing a grid of objects (squares as in a crossword puzzle).

>>What

>>I would like to do is have a CList within a CList. Something like:

>>

>>CList<Square, Square&>SquareList;

>>CList<SquareList, SquareList&>SquareGrid;

>>

>>However, I get a syntax error on the second definition (syntax error:

>>'>').

>>I guess I could break it down into two separate CList and correlate the

>>two,

>>but I was hoping someone would know how define a nested CList.

>>

>>Thanks in advance,

>

>This may not be the problem but have you tried using typedef?

>

>typedef CList<Square, Square&>SquareList;

>typedef CList<SquareList, SquareList&>SquareGrid;

>

>What you have is declaring a variable of type CList<Square, Square&>, not

>an

>assignable datatype. So the typedef should clear that up.

>

>--

>============

>Frank Hickman

>Microsoft MVP

>NobleSoft, Inc.

>============

>Replace the _nosp@m_ with @ to reply.

>

>

>





-

Re:Nested CList

Your latest version answered all the remaining questions. But it still

doesn't compile cleanly (the typedef definition for SquareGrid isn't quite

right - sorry I missed it in the earlier message). I took your code, created

and compiled it standalone (or at least tried). However, I get 2 compile

errors that go away when I comment out the typedef for SquareGrid. The error

message is a little confusing, but here it is:



error C2582: 'operator=' function is unavailable in 'CList<TYPE,ARG_TYPE>

with [TYPE=Square, ARG_TYPE=Square&].

error C2582: 'operator=' function is unavailable in 'CList<TYPE,ARG_TYPE>

with [TYPE=Square, ARG_TYPE=Square&].



Maybe you can reproduce it yourself. The other odd thing is that the

compile error comes from afxtempl.h, not your standalone code. Sorry to keep

after you on this one, but I think this is the last problem to get through.

If you can just get my past this one, I think I'm home free.



Thanks for all the help.



"Frank Hickman [MVP]" wrote:



Quote
"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

news:D9AEF8AC-74C2-4014-835F-40E044563FE6@microsoft.com...

>Well, the good news is that your solution fixed the compiler error and I

>can

>actually AddTail to both CLists (SquareList and SquareGrid) to populate

>them.

>However, the bad news is that I can only retrieve info (GetAt or

>FindIndex)

>from SquareList (cast as Square), because it actually points to an object

>(Square) not a typdef. Casting the results of accessing SquareGrid as a

>CList or as a SquareList didnt' help, because both are typedefs. I think

>we're close, but I just need to somehow get at the SquareGrid CList first,

>before I can get the final answer from SquareList CList.

>

>What do you think?

>





How are you actually using them? Remember that using typedef does not

actually create an object so the two lines I suggested would still need to

be used in a declaration statement.



typedef CList<Square, Square&>SquareList;

typedef CList<SquareList, SquareList&>SquareGrid;



SquareGrid m_sq_grid;

Square sq(0,0,10,10);

SquareList sq_lst;

sq_lst.AddTail( sq );

m_sq_grid.AddTail( sq_lst );



// This should work as is, no casting should be needed...

POSITION pos= m_sq_grid.GetHeadPosition();

SquareList& sq_lst_ref= m_sq_grid.GetNext( pos );

POSITION posLst= sq_lst_ref.GetHeadPosition();

Square& sq_ref= sq_lst_ref.GetNext( pos );



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.





>"Frank Hickman [MVP]" wrote:

>

>>"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

>>news:9F33D3FE-5235-40E6-865E-D27DEAF82C55@microsoft.com...

>>>I'm constructing a grid of objects (squares as in a crossword puzzle).

>>>What

>>>I would like to do is have a CList within a CList. Something like:

>>>

>>>CList<Square, Square&>SquareList;

>>>CList<SquareList, SquareList&>SquareGrid;

>>>

>>>However, I get a syntax error on the second definition (syntax error:

>>>'>').

>>>I guess I could break it down into two separate CList and correlate the

>>>two,

>>>but I was hoping someone would know how define a nested CList.

>>>

>>>Thanks in advance,

>>

>>This may not be the problem but have you tried using typedef?

>>

>>typedef CList<Square, Square&>SquareList;

>>typedef CList<SquareList, SquareList&>SquareGrid;

>>

>>What you have is declaring a variable of type CList<Square, Square&>, not

>>an

>>assignable datatype. So the typedef should clear that up.

>>

>>--

>>============

>>Frank Hickman

>>Microsoft MVP

>>NobleSoft, Inc.

>>============

>>Replace the _nosp@m_ with @ to reply.

>>

>>

>>







-

Re:Nested CList

I also tried to define an operator= function for the Square class, but it

didn't get rid of the error message. Don't know if the error message is a

'red herring' or I didn't defne the operator= function properly (it compiled

fine), but I'm still stuck in the same spot. STL (vector) is starting to

look good. I'd just like to keep the code consistent.



Just an FYI.



"Frank Hickman [MVP]" wrote:



Quote
"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

news:D9AEF8AC-74C2-4014-835F-40E044563FE6@microsoft.com...

>Well, the good news is that your solution fixed the compiler error and I

>can

>actually AddTail to both CLists (SquareList and SquareGrid) to populate

>them.

>However, the bad news is that I can only retrieve info (GetAt or

>FindIndex)

>from SquareList (cast as Square), because it actually points to an object

>(Square) not a typdef. Casting the results of accessing SquareGrid as a

>CList or as a SquareList didnt' help, because both are typedefs. I think

>we're close, but I just need to somehow get at the SquareGrid CList first,

>before I can get the final answer from SquareList CList.

>

>What do you think?

>





How are you actually using them? Remember that using typedef does not

actually create an object so the two lines I suggested would still need to

be used in a declaration statement.



typedef CList<Square, Square&>SquareList;

typedef CList<SquareList, SquareList&>SquareGrid;



SquareGrid m_sq_grid;

Square sq(0,0,10,10);

SquareList sq_lst;

sq_lst.AddTail( sq );

m_sq_grid.AddTail( sq_lst );



// This should work as is, no casting should be needed...

POSITION pos= m_sq_grid.GetHeadPosition();

SquareList& sq_lst_ref= m_sq_grid.GetNext( pos );

POSITION posLst= sq_lst_ref.GetHeadPosition();

Square& sq_ref= sq_lst_ref.GetNext( pos );



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.



-

Re:Nested CList

"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

Quote
Your latest version answered all the remaining questions. But it still

doesn't compile cleanly (the typedef definition for SquareGrid isn't quite

right - sorry I missed it in the earlier message). I took your code,

created

and compiled it standalone (or at least tried). However, I get 2 compile

errors that go away when I comment out the typedef for SquareGrid. The

error

message is a little confusing, but here it is:



error C2582: 'operator=' function is unavailable in 'CList<TYPE,ARG_TYPE>

with [TYPE=Square, ARG_TYPE=Square&].

error C2582: 'operator=' function is unavailable in 'CList<TYPE,ARG_TYPE>

with [TYPE=Square, ARG_TYPE=Square&].



Maybe you can reproduce it yourself. The other odd thing is that the

compile error comes from afxtempl.h, not your standalone code. Sorry to

keep

after you on this one, but I think this is the last problem to get

through.

If you can just get my past this one, I think I'm home free.



Thanks for all the help.





I was afraid that you would get these as well...The reason is because the

CList does not provide copy/assignment/comparison operators for the types

being stored, that is unless they are basic data types (int, long, double,

etc...) What you need to do is create copy/assignment constructors/operator

overrides for your Square class and your SquareList class. The Square class

is pretty stright forward for this. The SquareList class is not because you

need to change the definition a little.



Attached is the source file I used for testing. You can cut & paste the

relevant code into your test project. You may also want to create an actual

class for SquareGrid similar to the one I created for SquareList.



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.



Quote
"Frank Hickman [MVP]" wrote:



>"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

>news:D9AEF8AC-74C2-4014-835F-40E044563FE6@microsoft.com...

>>Well, the good news is that your solution fixed the compiler error and

>>I

>>can

>>actually AddTail to both CLists (SquareList and SquareGrid) to populate

>>them.

>>However, the bad news is that I can only retrieve info (GetAt or

>>FindIndex)

>>from SquareList (cast as Square), because it actually points to an

>>object

>>(Square) not a typdef. Casting the results of accessing SquareGrid as

>>a

>>CList or as a SquareList didnt' help, because both are typedefs. I

>>think

>>we're close, but I just need to somehow get at the SquareGrid CList

>>first,

>>before I can get the final answer from SquareList CList.

>>

>>What do you think?

>>

>

>

>How are you actually using them? Remember that using typedef does not

>actually create an object so the two lines I suggested would still need

>to

>be used in a declaration statement.

>

>typedef CList<Square, Square&>SquareList;

>typedef CList<SquareList, SquareList&>SquareGrid;

>

>SquareGrid m_sq_grid;

>Square sq(0,0,10,10);

>SquareList sq_lst;

>sq_lst.AddTail( sq );

>m_sq_grid.AddTail( sq_lst );

>

>// This should work as is, no casting should be needed...

>POSITION pos= m_sq_grid.GetHeadPosition();

>SquareList& sq_lst_ref= m_sq_grid.GetNext( pos );

>POSITION posLst= sq_lst_ref.GetHeadPosition();

>Square& sq_ref= sq_lst_ref.GetNext( pos );

>

>--

>============

>Frank Hickman

>Microsoft MVP

>NobleSoft, Inc.

>============

>Replace the _nosp@m_ with @ to reply.

>

>

>>"Frank Hickman [MVP]" wrote:

>>

>>>"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in

>>>message

>>>news:9F33D3FE-5235-40E6-865E-D27DEAF82C55@microsoft.com...

>>>>I'm constructing a grid of objects (squares as in a crossword

>>>>puzzle).

>>>>What

>>>>I would like to do is have a CList within a CList. Something like:

>>>>

>>>>CList<Square, Square&>SquareList;

>>>>CList<SquareList, SquareList&>SquareGrid;

>>>>

>>>>However, I get a syntax error on the second definition (syntax

>>>>error:

>>>>'>').

>>>>I guess I could break it down into two separate CList and correlate

>>>>the

>>>>two,

>>>>but I was hoping someone would know how define a nested CList.

>>>>

>>>>Thanks in advance,

>>>

>>>This may not be the problem but have you tried using typedef?

>>>

>>>typedef CList<Square, Square&>SquareList;

>>>typedef CList<SquareList, SquareList&>SquareGrid;

>>>

>>>What you have is declaring a variable of type CList<Square, Square&>,

>>>not

>>>an

>>>assignable datatype. So the typedef should clear that up.

>>>

>>>--

>>>============

>>>Frank Hickman

>>>Microsoft MVP

>>>NobleSoft, Inc.

>>>============

>>>Replace the _nosp@m_ with @ to reply.

>>>

>>>

>>>

>

>

>







begin 666 Square.cpp

M+R\@4W%U87)E+F-P<" Z($1E9FEN97,@=&AE(&5N=')Y('!O:6YT(&9O<B!T

M:&4@8V]N<V]L92!A<'!L:6-A=&EO;BX-"B\O#0H-"B-I;F-L=61E(")S=&1A

M9G@N:"(-"B-I;F-L=61E(")#;VYS;VQE+F@B#0H-"B-I;F-L=61E(")T;6%P

M<RYH(@T*#0HC:69D968@7T1%0E5'#0HC9&5F:6YE(&YE=R!$14)51U].15<-

M"B-U;F1E9B!42$E37T9)3$4-"G-T871I8R!C:&%R(%1(25-?1DE,15M=(#T@

M7U]&24Q%7U\[#0HC96YD:68-"@T*+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O

M+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O

M+R\O+R\O+R\-"B\O(%1H92!O;F4@86YD(&]N;'D@87!P;&EC871I;VX@;V)J

M96-T#0H-"D-7:6Y!<' @=&AE07!P.PT*#0HO+R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94QI<W0@<W%?;'-T,CT@<W%?;'-T.PT*"0EI9B H

M('-Q7VQS=" ]/2!S<5]L<W0R("D-"@D)>PT*"0D)8V]U=" \/"!?5"@B3&ES

M=',@87)E(&5Q=6%L+B(I(#P\(&5N9&P[#0H)"7T-"@D)96QS90T*"0E[#0H)

M"0EC;W5T(#P\(%]4*"),:7-T<R!A<F4@;F]T(&5Q=6%L+B(I(#P\(&5N9&P[

M#0H)"7T-"@T*"0E3<75A<F5'<FED('-Q7V=R:60[#0H)"7-Q7V=R:60N061D

M5&%I;"@@<W%?;'-T("D[#0H)"7-Q7V=R:60N061D5&%I;"@@<W%?;'-T,B I

M.PT*#0H)"7-Q7VQS="Y296UO=F5!;&PH*3L-"@D)<W%?;'-T,BY296UO=F5!

M;&PH*3L-"@T*"0DO+R!2979E<G-E('1H92!R969E<F5N8V5S+BXN#0H)"5!/

M4TE424].('!O<ST@<W%?9W)I9"Y'971(96%D4&]S:71I;VXH*3L-"@D)<W%?

M;'-T,CT@<W%?9W)I9"Y'971.97AT*"!P;W,@*3L-"@D)<W%?;'-T/2!S<5]G

M<FED+D=E=$YE>'0H('!O<R I.PT*#0H)"6EF("@@<W%?;'-T(#T]('-Q7VQS

M=#(@*0T*"0E[#0H)"0EC;W5T(#P\(%]4*"),:7-T<R!A<F4@97%U86PN(BD@

M/#P@96YD;#L-"@D)?0T*"0EE;'-E#0H)"7L-"@D)"6-O=70@/#P@7U0H(DQI

M<W1S(&%R92!N;W0@97%U86PN(BD@/#P@96YD;#L-"@D)?0T*"7T-"@T*"5!2

D15-37T%.65]+15D[#0H)<F5T=7)N(&Y2971#;V1E.PT*?0T*

`

end



-

Re:Nested CList

Thanks for all your help. I ended up writing a wrapper class for CList and

adding the missing operators/methods. It seems to work fine. However, I

appreciate you including your solution as I learned a few new tricks from it.



Regards,



Quote
I was afraid that you would get these as well...The reason is because the

CList does not provide copy/assignment/comparison operators for the types

being stored, that is unless they are basic data types (int, long, double,

etc...) What you need to do is create copy/assignment constructors/operator

overrides for your Square class and your SquareList class. The Square class

is pretty stright forward for this. The SquareList class is not because you

need to change the definition a little.



Attached is the source file I used for testing. You can cut & paste the

relevant code into your test project. You may also want to create an actual

class for SquareGrid similar to the one I created for SquareList.



--

============

Frank Hickman

Microsoft MVP

NobleSoft, Inc.

============

Replace the _nosp@m_ with @ to reply.



>"Frank Hickman [MVP]" wrote:

>

>>"Triplesticks" <Triplesticks@discussions.microsoft.com>wrote in message

>>news:D9AEF8AC-74C2-4014-835F-40E044563FE6@microsoft.com...

>>>Well, the good news is that your solution fixed the compiler error and

>>>I

>>>can

>>>actually AddTail to both CLists (SquareList and SquareGrid) to populate

>>>them.

>>>However, the bad news is that I can only retrieve info (GetAt or

>>>FindIndex)

>>>from SquareList (cast as Square), because it actually points to an

>>>object

>>>(Square) not a typdef. Casting the results of accessing SquareGrid as

>>>a

>>>CList or as a SquareList didnt' help, because both are typedefs. I

>>>think

>>>we're close, but I just need to somehow get at the SquareGrid CList

>>>first,

>>>before I can get the final answer from SquareList CList.

>>>

>>>What do you think?

>>>

>>

>>

>>How are you actually using them? Remember that using typedef does not

>>actually create an object so the two lines I suggested would still need

>>to

>>be used in a declaration statement.

>>

>>typedef CList<Square, Square&>SquareList;

>>typedef CList<SquareList, SquareList&>SquareGrid;

>>

>>SquareGrid m_sq_grid;

>>Square sq(0,0,10,10);

>>SquareList sq_lst;

>>sq_lst.AddTail( sq );

>>m_sq_grid.AddTail( sq_lst );

>>

>>// This should work as is, no casting should be needed...

>>POSITION pos= m_sq_grid.GetHeadPosition();

>>SquareList& sq_lst_ref= m_sq_grid.GetNext( pos );

>>POSITION posLst= sq_lst_ref.GetHeadPosition();

>>Square& sq_ref= sq_lst_ref.GetNext( pos );

>>

>>--

>>============

>>Frank Hickman

>>Microsoft MVP

>>NobleSoft, Inc.

>>============

>>Replace the _nosp@m_ with @ to reply.

>>

>>



-