forcing c++ to use an overloaded method

  • Thread starter mrbrightsidestolemymoney
  • Start date
M

mrbrightsidestolemymoney

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
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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!!].

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
 
A

Azumanga

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!!].

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
 
M

Michiel.Salters

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.

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,
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top