470,821 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

forcing c++ to use an overloaded method

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

May 31 '06 #1
3 1519
On 2006-05-31 22:21, mr**********************@googlemail.com wrote:
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
--
"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
May 31 '06 #2
mr**********************@googlemail.com wrote:
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

May 31 '06 #3

mr**********************@googlemail.com wrote:
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

Jun 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

44 posts views Thread by bahadir.balban | last post: by
1 post views Thread by Alex Zhitlenok | last post: by
10 posts views Thread by john bailo | last post: by
3 posts views Thread by cybertof | last post: by
2 posts views Thread by Saradhi | last post: by
1 post views Thread by Alan | last post: by
9 posts views Thread by Lawrence Krubner | last post: by
3 posts views Thread by sam.barker0 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.