R
RobertEstelle
Hello,
I've been banging my head against this problem for a couple hours now
to no avail.
I'm trying to make a descendant of a class that has overloaded methods
with variable argument lists. The problem is, when my descendant class
does the same, function resolution seems to stop there without looking
at the base class.
This happens both with g++ and VS2005, so I don't suspect it's a
compiler bug.
Note that I'm just trying to inherit these methods (which are
overloaded on name), not override their implementation.
Here's a trivial example:
/////~ begin code ~/////
class T1 {};
class T2 {};
class A
{
public:
int Get(T1&, char const*, ...);
int Get(double&, char const*, ...);
};
class B : public A
{
public:
int Get(T2&, char const*, ...);
int Get(int&, char const*, ...);
};
int main(int argc, char** argv)
{
B b;
T1 t1;
// Would expect it to call A::Get(T1&, char const*, ...);
// but it doesn't; it errors out saying that B:T2&, char
const*, ...)
// can't cast the first operator.
return b.Get(t1, "Foo", 15);
}
/////~ end code ~/////
The actual error message g++ puts out is:
vatest.cpp: In function `int main(int, char**)':
vatest.cpp:25: error: no matching function for call to `B::Get(T1&,
const char[5])'
vatest.cpp:14: note: candidates are: int B::Get(T2&, const char*, ...)
vatest.cpp:15: note: int B::Get(int&, const char*, ...)
This seems pretty puzzling to me -- it doesn't even look at the
methods A provides!
If I declare all of A's methods in B (e.g., if I were to make them
virtual and provide my own implementations in every overriding class),
resolution works just fine; but then I'm left with the problem of
implementing them all by manually passing a va_list to the
base...something that seems very hacky and dangerous.
Can anyone shed some light on this?
Thanks,
Robert Estelle
I've been banging my head against this problem for a couple hours now
to no avail.
I'm trying to make a descendant of a class that has overloaded methods
with variable argument lists. The problem is, when my descendant class
does the same, function resolution seems to stop there without looking
at the base class.
This happens both with g++ and VS2005, so I don't suspect it's a
compiler bug.
Note that I'm just trying to inherit these methods (which are
overloaded on name), not override their implementation.
Here's a trivial example:
/////~ begin code ~/////
class T1 {};
class T2 {};
class A
{
public:
int Get(T1&, char const*, ...);
int Get(double&, char const*, ...);
};
class B : public A
{
public:
int Get(T2&, char const*, ...);
int Get(int&, char const*, ...);
};
int main(int argc, char** argv)
{
B b;
T1 t1;
// Would expect it to call A::Get(T1&, char const*, ...);
// but it doesn't; it errors out saying that B:T2&, char
const*, ...)
// can't cast the first operator.
return b.Get(t1, "Foo", 15);
}
/////~ end code ~/////
The actual error message g++ puts out is:
vatest.cpp: In function `int main(int, char**)':
vatest.cpp:25: error: no matching function for call to `B::Get(T1&,
const char[5])'
vatest.cpp:14: note: candidates are: int B::Get(T2&, const char*, ...)
vatest.cpp:15: note: int B::Get(int&, const char*, ...)
This seems pretty puzzling to me -- it doesn't even look at the
methods A provides!
If I declare all of A's methods in B (e.g., if I were to make them
virtual and provide my own implementations in every overriding class),
resolution works just fine; but then I'm left with the problem of
implementing them all by manually passing a va_list to the
base...something that seems very hacky and dangerous.
Can anyone shed some light on this?
Thanks,
Robert Estelle