Connecting Tech Pros Worldwide Forums | Help | Site Map

forcing c++ to use an overloaded method

mrbrightsidestolemymoney@googlemail.com
Guest
 
Posts: n/a
#1: May 31 '06
Hi,

I need to write out a 1d array of 2d arrays (the structures for each
are custom, a 3d structure is defined but not suitable for my use for a
number of reasons).

Templated routines exist for writing out multi2d<T> and multi1d<T>,
hence writing multi2d<multi1d<T>> is possible, although fails for some
unknown reason. There is a multi3d<T> writer, but like I said...

Is it possible to define my own write routine which will write out a
multi2d<multi1d<T>> yet NOT have the compiler (g++) complain that there
is an ambiguity introduced by the already existing multi2d<T> and
multi1d<T> writers combined? I want to call it the same (i.e. write)
and pass the same arguments, to keep a consistency --- this is a large
project so any hacked solutions tend to get kicked out when the
branches merge [even this solution might be too hacked!!].

Cheers,
chris


Erik Wikström
Guest
 
Posts: n/a
#2: May 31 '06

re: forcing c++ to use an overloaded method


On 2006-05-31 22:21, mrbrightsidestolemymoney@googlemail.com wrote:[color=blue]
> Hi,
>
> I need to write out a 1d array of 2d arrays (the structures for each
> are custom, a 3d structure is defined but not suitable for my use for a
> number of reasons).
>
> Templated routines exist for writing out multi2d<T> and multi1d<T>,
> hence writing multi2d<multi1d<T>> is possible, although fails for some
> unknown reason. There is a multi3d<T> writer, but like I said...
>
> Is it possible to define my own write routine which will write out a
> multi2d<multi1d<T>> yet NOT have the compiler (g++) complain that there
> is an ambiguity introduced by the already existing multi2d<T> and
> multi1d<T> writers combined? I want to call it the same (i.e. write)
> and pass the same arguments, to keep a consistency --- this is a large
> project so any hacked solutions tend to get kicked out when the
> branches merge [even this solution might be too hacked!!].[/color]

I'm not exactly sure what you are getting at (getting late over here)
but if you want to make your own implementation of the template routines
mentioned above and be sure that your's are called you could place them
in a separate namespace and explicitly calling these. I believe that you
could then do something like

using my_space::multi2d;
using my_space::multi1d;

and you wouldn't need to prefix each call since this would tell the
compiler that it's your version you want.

Erik Wikström
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup
Azumanga
Guest
 
Posts: n/a
#3: May 31 '06

re: forcing c++ to use an overloaded method


mrbrightsidestolemymoney@googlemail.com wrote:[color=blue]
> Hi,
>
> I need to write out a 1d array of 2d arrays (the structures for each
> are custom, a 3d structure is defined but not suitable for my use for a
> number of reasons).
>
> Templated routines exist for writing out multi2d<T> and multi1d<T>,
> hence writing multi2d<multi1d<T>> is possible, although fails for some
> unknown reason. There is a multi3d<T> writer, but like I said...
>
> Is it possible to define my own write routine which will write out a
> multi2d<multi1d<T>> yet NOT have the compiler (g++) complain that there
> is an ambiguity introduced by the already existing multi2d<T> and
> multi1d<T> writers combined? I want to call it the same (i.e. write)
> and pass the same arguments, to keep a consistency --- this is a large
> project so any hacked solutions tend to get kicked out when the
> branches merge [even this solution might be too hacked!!].
>[/color]

I'm afraid you are going to have to be more clear on exactly what is
and is not working. I've written the kind of code you seem to be
describing in both ways, and had it work. Producing a small example of
code which does not work would probably both help you understand the
problem, and help us fix it.

Chris

Michiel.Salters@tomtom.com
Guest
 
Posts: n/a
#4: Jun 1 '06

re: forcing c++ to use an overloaded method



mrbrightsidestolemymoney@googlemail.com wrote:[color=blue]
> Hi,
>
> I need to write out a 1d array of 2d arrays (the structures for each
> are custom, a 3d structure is defined but not suitable for my use for a
> number of reasons).
>
> Templated routines exist for writing out multi2d<T> and multi1d<T>,
> hence writing multi2d<multi1d<T>> is possible, although fails for some
> unknown reason.[/color]

Probaly a very trivial one, "maximum-munch". >> is a left-shift. It's a
single
token, not two > > tokens. If you add a space between the two
characters,
it will probably work. For the same reason, >>> and >>>> are two
tokens,
[color=blue]
> Is it possible to define my own write routine which will write out a
> multi2d<multi1d<T>> yet NOT have the compiler (g++) complain that there
> is an ambiguity introduced by the already existing multi2d<T> and
> multi1d<T> writers combined?[/color]

How do we know? You haven't shown us a bit of code.

If you just give your writer a unique name, and call it by that unique
name
- not overloaded in any sense - it will just work. Just use a GUID in
the
name if you really want it to be sure it's unique.

HTH,
Michiel Salters

Closed Thread