From: Dave Symonds on
On 6/22/05, Gad Zooks <gad_zooks(a)hotmail.co.uk> wrote:

[... lots of code snipped ...]

> Which generates the following error:
>
> C:\DataLynx\Development\DataLynx_GUI\DataLynxETL_v2\example.cpp(57) :
> error C2664: 'Sort' : cannot convert parameter 1 from
> 'int (const class Example *,const class Example *)'
> to
> 'int (__cdecl *)(class Example ** ,class Example ** )'
> None of the functions with this name in scope match the target type

Here's your primary mistake: you misunderstood what the contents of
your wxArray was.
>From your code (that I've snipped out), you were putting Example*
(i.e. pointer to Example) things into your array. The array doesn't
care about the types, but it calls the sort function that you provide
with two pointers to the content -- in this case, pointers to Example*
-- and so your function should take, in this case, Example**.

> and .... it compiles ..... <furtively tests that it is working > ....
> um .... and works ....
>
> I can't believe it - I was at this til 1am last night!

Yeah, been there, done that (heh!). Often these problems only work
themselves out when you try to explain it to someone else. Experience
helps, as well. Careful with those pointers!

> Actually I do think that I am still not using this as it was intended;
> the manual says :
>
> wxArray::Sort
> void Sort(CMPFUNC<T> compareFunction)
>
> The notation CMPFUNC<T> should be read as if we had
> the following declaration:
>
> template int CMPFUNC(T *first, T *second);
>
> where T is the type of the array elements. I.e. it is a
> function returning int which is passed two arguments
> of type T *.
>
> and I am somehow having to use pointers to pointers, is there still
> something I am doing wrong ?

The manual is correct, but you are misunderstanding it: in your
example above, the T type is actually Example* (the content type of
the wxArray), and so your function takes T*, which is Example**.

> I'd like to be able to say that if ever I can help you with a problem
> you are having .... but on this basis it's not likely is it ?

Heh, I'm not too proud to ask for help when I need it. I've got 15
years programming experience, but I still need to bounce things off
people occasionally. It is often the quickest way to solving silly
little problems like these.


Dave.

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Stavros Tsolakos on

>and I am somehow having to use pointers to pointers, is there still
>something I am doing wrong ?
>
>
In fact, object arrays contain *pointers* to the real objects. This is
why this function takes pointer to pointer. Have a look at the manual:

http://www.wxwidgets.org/manuals/2.6.1/wx_wxarray.html#wxdefineobjarray

HTH,
Stavros

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Gad Zooks on
On Wed, 22 Jun 2005 13:22:39 +0000 (UTC), stsolakos(a)patras.atmel.com
(Stavros Tsolakos) wrote:

>In fact, object arrays contain *pointers* to the real objects. This is
>why this function takes pointer to pointer. Have a look at the manual:
>
>http://www.wxwidgets.org/manuals/2.6.1/wx_wxarray.html#wxdefineobjarray
>

Dave, Stavros,

I am now more edumacated in the ways of wxArrays.

Thanks for your help chaps,

Gad

From: Marc Lindahl on

On Jun 22, 2005, at 7:11 AM, Gad Zooks wrote:

>
> if((res = strcmp( A->field1, B->field1 )))
> return(res);


shouldn't it be a '==' instead of a '='?


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Chris Wilson on
Hi Marc,

>> if((res = strcmp( A->field1, B->field1 )))
>> return(res);
>
> shouldn't it be a '==' instead of a '='?

Are you sure? It looks like a standard (if counter-intuitive) C idiom for
assignment and comparison in the same statement, perhaps better written
as:

res = strcmp( A->field1, B->field1 );
if (res)
return res;


But it has the same effect.

Cheers, Chris.
--
_ ___ __ _
/ __/ / ,__(_)_ | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Next: determining image resolution (dpi)