![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Fredrik Eriksson wrote:
> On Wed, 14 May 2008 18:23:54 +0200, Darren New <dne### [at] san rr com> wrote:
>>
>> *** Main2.cpp
>>
>> #include <A.h>
>>
>> void A::xx(int i) {
>> cout << "Beta!\n";
>> }
>
> This will fail to compile, because you cannot redefine A::xx.
I didn't. I created an overloaded version. One takes an int, the other
takes a long. Am I *completely* clueless about C++?
My intent was to get one match to do a silent upcast from int to long,
and the other to match the more-appropriate int-accepting function.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Fredrik Eriksson
Subject: Re: A question about Java generics (not a flame)
Date: 14 May 2008 17:01:28
Message: <op.ua5woqdy7bxctx@e6600>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Wed, 14 May 2008 22:52:33 +0200, Darren New <dne### [at] san rr com> wrote:
> Fredrik Eriksson wrote:
>> On Wed, 14 May 2008 18:23:54 +0200, Darren New <dne### [at] san rr com> wrote:
>>>
>>> *** Main2.cpp
>>>
>>> #include <A.h>
>>>
>>> void A::xx(int i) {
>>> cout << "Beta!\n";
>>> }
>> This will fail to compile, because you cannot redefine A::xx.
>
> I didn't. I created an overloaded version. One takes an int, the other
> takes a long. Am I *completely* clueless about C++?
You cannot add overloads to class methods from outside the class. All
overloads must be declared in the class declaration.
--
FE
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Fredrik Eriksson wrote:
> You cannot add overloads to class methods from outside the class. All
> overloads must be declared in the class declaration.
Thanks!
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 15 May 2008 08:45:40
Message: <482c3074@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> *** A.h
> void X<T>(void);
> class A {
> void xx(long i) {
> cout << "Alpha!\n";
> }
> }
> #include <A.h>
> void A::xx(int i) {
> cout << "Beta!\n";
> }
You are trying to implement a function void A::xx(int) which hasn't
been declared in the class A declaration. It won't compile.
Note that void A::xx(long) and void A::xx(int) are two different functions,
with different fingerprints. You cannot override one with the other.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 15 May 2008 08:49:55
Message: <482c3173@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> Now make a small change to main.cpp:
> // main.cpp
> export template <typename T> void f();
> #include "g.hpp"
> template <> void g(int i) { /* Do something completely different */ }
> int main(){ f<int>(); }
> // end main.cpp
I don't see how this causes a problem described earlier. This simply
requires main.cpp to be recompiled (after all, it's the one which has
been changed), which will result in a new object file which does not
use the export template.
Why would this cause the need to recompile the export template for
each usage in the program?
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> You are trying to implement a function void A::xx(int) which hasn't
> been declared in the class A declaration. It won't compile.
That I didn't know. Will it work if you just make xx(int) and xx(long)
globals?
> Note that void A::xx(long) and void A::xx(int) are two different functions,
> with different fingerprints. You cannot override one with the other.
Well, I was trying to overload, not override as such.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 15 May 2008 12:07:59
Message: <482c5fdf@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> That I didn't know. Will it work if you just make xx(int) and xx(long)
> globals?
Maybe what you are trying to write is something like this:
foo.cc:
export template<typename T>
void foo(T t) { bar(t); }
a.cc:
export template<typename T>
void foo(T t);
void bar(int i);
void a() { foo(5); }
b.cc:
export template<typename T>
void foo(T t);
void bar(long i);
void b() { foo(5); }
I see how that could make some difference.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: A question about Java generics (not a flame)
Date: 15 May 2008 12:12:17
Message: <482c60e1@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp <war### [at] tag povray org> wrote:
> foo.cc:
> export template<typename T>
> void foo(T t) { bar(t); }
> I see how that could make some difference.
OTOH, thinking about it: There's no function named 'bar' defined anywhere
in the scope of foo.cc, so why should that even compile?
I have to admit I don't know if the C++ standard requires the environment
of the instantation of the template when compiling the template function or
not. Personally I wouldn't find it illogical if foo.cc above would cause
a compiler error because, after all, there's no 'bar()' function defined
there.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> Maybe what you are trying to write is something like this:
Something like that, yeah. Something where the overload resolution in
the expanded template requires it to be calling different functions
depending on declarations that came in the main program before the
instantiation of the template.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Darren New
Subject: Re: A question about Java generics (not a flame)
Date: 15 May 2008 12:35:19
Message: <482c6647@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> OTOH, thinking about it: There's no function named 'bar' defined anywhere
> in the scope of foo.cc, so why should that even compile?
Move the declaration of bar(long) into foo.cc? Then if there's a
bar(int) in scope, it should be preferred over bar(long), if I follow
the overloading rules properly?
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |