Child class calling unexpected overloaded functionWhat are the rules for calling the superclass constructor?Use 'class' or 'typename' for template parameters?How to call a parent class function from derived class function?Function overloading in Javascript - Best practicesCall a parent class's method from child class in Python?Python class inherits objectWhat are the basic rules and idioms for operator overloading?Template function overloading with identical signatures, why does this work?Overloading base method in derived classUnexpected overload resolution in visual studio involving void*, string and const char[]
"It will become the talk of Paris" - translation into French
Are there any vegetarian astronauts?
Going to get married soon, should I do it on Dec 31 or Jan 1?
What are the penalties for overstaying in USA?
How well known and how commonly used was Huffman coding in 1979?
How can I convince my reader that I will not use a certain trope?
Bash echo $-1 prints hb1. Why?
Does ultrasonic bath cleaning damage laboratory volumetric glassware calibration?
Is there any set of 2-6 notes that doesn't have a chord name?
Why does the A-4 Skyhawk sit nose-up when on ground?
Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?
Short story with brother-sister conjoined twins as protagonists?
Ending: accusative or not?
Is it OK to bottle condition using previously contaminated bottles?
Find smallest index that is identical to the value in an array
Why does adding parentheses prevent an error?
Counting occurrence of words in table is slow
Does image quality of the lens affect "focus and recompose" technique?
How many satellites can stay in a Lagrange point?
Simple object validator with a new API
How risky is real estate?
Is my Rep in Stack-Exchange Form?
Using “sparkling” as a diminutive of “spark” in a poem
Analog is Obtuse!
Child class calling unexpected overloaded function
What are the rules for calling the superclass constructor?Use 'class' or 'typename' for template parameters?How to call a parent class function from derived class function?Function overloading in Javascript - Best practicesCall a parent class's method from child class in Python?Python class inherits objectWhat are the basic rules and idioms for operator overloading?Template function overloading with identical signatures, why does this work?Overloading base method in derived classUnexpected overload resolution in visual studio involving void*, string and const char[]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm struggling to understand why in the following code the supposedly wrong overload is being called.
// overload.h
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(args...);
;
struct T2 : public T1
void doFoo(char c)
std::cout << "T2 doFoo char " << std::endl;
;
// main.cpp
#include <overload.h>
int main()
T2 t2;
t2.foo(3);
t2.foo('A'); // This outputs: T1 doFoo generic
I was expecting that t2.foo('A') had as output: "T2 doFoo char", but instead I got "T1 doFoo generic".
If I move T2::doFoo(char c) into T1, everything works as expected. What's the reason of this behavior? any workaround?
c++ templates inheritance overloading template-meta-programming
|
show 2 more comments
I'm struggling to understand why in the following code the supposedly wrong overload is being called.
// overload.h
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(args...);
;
struct T2 : public T1
void doFoo(char c)
std::cout << "T2 doFoo char " << std::endl;
;
// main.cpp
#include <overload.h>
int main()
T2 t2;
t2.foo(3);
t2.foo('A'); // This outputs: T1 doFoo generic
I was expecting that t2.foo('A') had as output: "T2 doFoo char", but instead I got "T1 doFoo generic".
If I move T2::doFoo(char c) into T1, everything works as expected. What's the reason of this behavior? any workaround?
c++ templates inheritance overloading template-meta-programming
Do you callt2.foo('A');
ort2.doFoo('A');
? I think if you would callt2.doFoo('A');
you wold get the correct result.
– vahancho
Mar 25 at 11:25
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
I see, but it looks like you expect thatT1::foo<...>
call thedoFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.
– vahancho
Mar 25 at 11:30
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
Why do you expectT1::foo
to call a function in theT2
class?T1
doesn't know aboutT2
. When it callsdoFoo
, the type ofthis
isT1 *
.
– 1201ProgramAlarm
Mar 25 at 15:02
|
show 2 more comments
I'm struggling to understand why in the following code the supposedly wrong overload is being called.
// overload.h
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(args...);
;
struct T2 : public T1
void doFoo(char c)
std::cout << "T2 doFoo char " << std::endl;
;
// main.cpp
#include <overload.h>
int main()
T2 t2;
t2.foo(3);
t2.foo('A'); // This outputs: T1 doFoo generic
I was expecting that t2.foo('A') had as output: "T2 doFoo char", but instead I got "T1 doFoo generic".
If I move T2::doFoo(char c) into T1, everything works as expected. What's the reason of this behavior? any workaround?
c++ templates inheritance overloading template-meta-programming
I'm struggling to understand why in the following code the supposedly wrong overload is being called.
// overload.h
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(args...);
;
struct T2 : public T1
void doFoo(char c)
std::cout << "T2 doFoo char " << std::endl;
;
// main.cpp
#include <overload.h>
int main()
T2 t2;
t2.foo(3);
t2.foo('A'); // This outputs: T1 doFoo generic
I was expecting that t2.foo('A') had as output: "T2 doFoo char", but instead I got "T1 doFoo generic".
If I move T2::doFoo(char c) into T1, everything works as expected. What's the reason of this behavior? any workaround?
c++ templates inheritance overloading template-meta-programming
c++ templates inheritance overloading template-meta-programming
edited Mar 25 at 13:54
Saturnu
asked Mar 25 at 11:12
SaturnuSaturnu
977 bronze badges
977 bronze badges
Do you callt2.foo('A');
ort2.doFoo('A');
? I think if you would callt2.doFoo('A');
you wold get the correct result.
– vahancho
Mar 25 at 11:25
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
I see, but it looks like you expect thatT1::foo<...>
call thedoFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.
– vahancho
Mar 25 at 11:30
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
Why do you expectT1::foo
to call a function in theT2
class?T1
doesn't know aboutT2
. When it callsdoFoo
, the type ofthis
isT1 *
.
– 1201ProgramAlarm
Mar 25 at 15:02
|
show 2 more comments
Do you callt2.foo('A');
ort2.doFoo('A');
? I think if you would callt2.doFoo('A');
you wold get the correct result.
– vahancho
Mar 25 at 11:25
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
I see, but it looks like you expect thatT1::foo<...>
call thedoFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.
– vahancho
Mar 25 at 11:30
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
Why do you expectT1::foo
to call a function in theT2
class?T1
doesn't know aboutT2
. When it callsdoFoo
, the type ofthis
isT1 *
.
– 1201ProgramAlarm
Mar 25 at 15:02
Do you call
t2.foo('A');
or t2.doFoo('A');
? I think if you would call t2.doFoo('A');
you wold get the correct result.– vahancho
Mar 25 at 11:25
Do you call
t2.foo('A');
or t2.doFoo('A');
? I think if you would call t2.doFoo('A');
you wold get the correct result.– vahancho
Mar 25 at 11:25
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
I see, but it looks like you expect that
T1::foo<...>
call the doFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.– vahancho
Mar 25 at 11:30
I see, but it looks like you expect that
T1::foo<...>
call the doFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.– vahancho
Mar 25 at 11:30
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
Why do you expect
T1::foo
to call a function in the T2
class? T1
doesn't know about T2
. When it calls doFoo
, the type of this
is T1 *
.– 1201ProgramAlarm
Mar 25 at 15:02
Why do you expect
T1::foo
to call a function in the T2
class? T1
doesn't know about T2
. When it calls doFoo
, the type of this
is T1 *
.– 1201ProgramAlarm
Mar 25 at 15:02
|
show 2 more comments
1 Answer
1
active
oldest
votes
As already suggested in comment, since T1
doesn't know about the derived struct T2
, T1::foo
also can not find T2::doFoo(char c)
and this static binding can not be achieved.
A simple workaround to spuriously overload T1::foo
for char
in T2
would be again declaring foo
in T2
and overloading it as follows:
DEMO
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(std::forward<Args>(args)...);
;
struct T2 : public T1
template<class... Args>
void foo(Args&&... args)
T1::foo(std::forward<Args>(args)...);
void foo(char c)
std::cout << "T2 foo char " << std::endl;
;
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336516%2fchild-class-calling-unexpected-overloaded-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As already suggested in comment, since T1
doesn't know about the derived struct T2
, T1::foo
also can not find T2::doFoo(char c)
and this static binding can not be achieved.
A simple workaround to spuriously overload T1::foo
for char
in T2
would be again declaring foo
in T2
and overloading it as follows:
DEMO
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(std::forward<Args>(args)...);
;
struct T2 : public T1
template<class... Args>
void foo(Args&&... args)
T1::foo(std::forward<Args>(args)...);
void foo(char c)
std::cout << "T2 foo char " << std::endl;
;
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
|
show 5 more comments
As already suggested in comment, since T1
doesn't know about the derived struct T2
, T1::foo
also can not find T2::doFoo(char c)
and this static binding can not be achieved.
A simple workaround to spuriously overload T1::foo
for char
in T2
would be again declaring foo
in T2
and overloading it as follows:
DEMO
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(std::forward<Args>(args)...);
;
struct T2 : public T1
template<class... Args>
void foo(Args&&... args)
T1::foo(std::forward<Args>(args)...);
void foo(char c)
std::cout << "T2 foo char " << std::endl;
;
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
|
show 5 more comments
As already suggested in comment, since T1
doesn't know about the derived struct T2
, T1::foo
also can not find T2::doFoo(char c)
and this static binding can not be achieved.
A simple workaround to spuriously overload T1::foo
for char
in T2
would be again declaring foo
in T2
and overloading it as follows:
DEMO
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(std::forward<Args>(args)...);
;
struct T2 : public T1
template<class... Args>
void foo(Args&&... args)
T1::foo(std::forward<Args>(args)...);
void foo(char c)
std::cout << "T2 foo char " << std::endl;
;
As already suggested in comment, since T1
doesn't know about the derived struct T2
, T1::foo
also can not find T2::doFoo(char c)
and this static binding can not be achieved.
A simple workaround to spuriously overload T1::foo
for char
in T2
would be again declaring foo
in T2
and overloading it as follows:
DEMO
struct T1
template<class... Args>
void doFoo(Args&&... args)
std::cout << "T1 doFoo generic"<< std::endl;
void doFoo(int a)
std::cout << "T1 doFoo INT "<< std::endl;
void doFoo(double a)
std::cout << "T1 doFoo Double "<< std::endl;
template<class... Args>
void foo(Args&&... args)
doFoo(std::forward<Args>(args)...);
;
struct T2 : public T1
template<class... Args>
void foo(Args&&... args)
T1::foo(std::forward<Args>(args)...);
void foo(char c)
std::cout << "T2 foo char " << std::endl;
;
edited Mar 26 at 6:23
answered Mar 25 at 19:29
HirokiHiroki
2,4753 gold badges5 silver badges22 bronze badges
2,4753 gold badges5 silver badges22 bronze badges
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
|
show 5 more comments
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Really interesting solution, probably it's what I was looking for. I'll try to test it, thank you for sharing!
– Saturnu
Mar 26 at 10:11
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
Do you think this solution could be extendable, I mean, something like creating a struct TFinal that inherits from T1, T3, T4 etc and that has a method foo() that in some ways knows all the overloads?
– Saturnu
Mar 26 at 10:51
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
@Saturnu Yes, this is definitely extendable like this. But this also looks verbose :). Hmm.. I think that there may be a more simple solution.
– Hiroki
Mar 26 at 13:58
1
1
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
interesting solution. Yep it seems extensible in that way, but it requires a fixed inheritance hierarchy while it could have been much better to have T2, T3, T4 etc and inherit only from the ones you need.. Difficult to achieve though
– Saturnu
Mar 26 at 14:12
1
1
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
no worries, your answer was more than good. The other would be the cherry on the cake eheh
– Saturnu
Mar 26 at 15:56
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336516%2fchild-class-calling-unexpected-overloaded-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you call
t2.foo('A');
ort2.doFoo('A');
? I think if you would callt2.doFoo('A');
you wold get the correct result.– vahancho
Mar 25 at 11:25
yes, that's true. My intention is though to make all the doFoo functions protected, so that the only interface is foo(). So I need to call foo(myargs)
– Saturnu
Mar 25 at 11:28
I see, but it looks like you expect that
T1::foo<...>
call thedoFoo
of a derived class, like a virtual function, but it will not work in that way - this is a static binding.– vahancho
Mar 25 at 11:30
It's not exaclty like a virtual function call. Statically, the compiler should be able to figure this overload out, as in this case it does not need runtime information. I am just looking for a way to make this happen without incurring in run-time overhead
– Saturnu
Mar 25 at 11:35
Why do you expect
T1::foo
to call a function in theT2
class?T1
doesn't know aboutT2
. When it callsdoFoo
, the type ofthis
isT1 *
.– 1201ProgramAlarm
Mar 25 at 15:02