F
fungus
I've got a big template class "A" and I want to write another template
"B" which is exactly the same as A except for one method (let's call
it "foo()").
Is there a way to do this without complete copy/paste of "A"? I'd like
to do it with only one copy of the common code.
nb. foo() can't be static, it needs access to class members....
template <class T> class A {
void foo();
};
template <class T> class B {
void foo(); // I want a different "foo()" here...
};
On a related note, something which came up while I was messing around
with this is that when I inherit from a class ("A"), all the
constructors in "A" are hidden.
class A {
public:
A(int);
};
class B : public A {
public:
// Compiler writes a constructor for me, hiding A(int)...
};
main() {
// Doesn't work...compiler says 'int' can't be converted to 'const
B&'
B b(42);
}
How can I make A's constructors visible? I read the faq and tried
adding
a "using A::A", but it makes no difference...
class B : public A {
public:
using A::A; // Makes no difference...
};
faq: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
"B" which is exactly the same as A except for one method (let's call
it "foo()").
Is there a way to do this without complete copy/paste of "A"? I'd like
to do it with only one copy of the common code.
nb. foo() can't be static, it needs access to class members....
template <class T> class A {
void foo();
};
template <class T> class B {
void foo(); // I want a different "foo()" here...
};
On a related note, something which came up while I was messing around
with this is that when I inherit from a class ("A"), all the
constructors in "A" are hidden.
class A {
public:
A(int);
};
class B : public A {
public:
// Compiler writes a constructor for me, hiding A(int)...
};
main() {
// Doesn't work...compiler says 'int' can't be converted to 'const
B&'
B b(42);
}
How can I make A's constructors visible? I read the faq and tried
adding
a "using A::A", but it makes no difference...
class B : public A {
public:
using A::A; // Makes no difference...
};
faq: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9