#include <iostream>
usingnamespace std;
// forward declares:
class B;
class A
{
public:
A() {}
virtual ~A() {}
void f1(A* a) {}
void f2(B* b) {}
};
class B : public A
{
public:
B():A() {}
virtual ~B() {}
};
int main()
{
A a;
B b;
}
#include <iostream>
usingnamespace std;
class B;
class A
{
public:
void f1(A a) {}
void f2(B b);
};
class B : public A
{
};
inlinevoid A::f2( B b ) {}
int main()
{
A a;
B b;
}
You declared different functions compared to functions in the original post. Also there is no need to specify explicitly the constructor of B and to call explicitly the constructor of A in the mem-intilaizer list of B().
Just because I pass the argument by a pointer doesn't mean that its wrong. It's also good practice to declare a default constructor and to call it's base class constructor. Why don't you tell me why not?
The default constructor for B will automatically call the default constructor for A, unless you specify different behaviour. There's no need to write it out in constructor for B - it's just code clutter.
@ajh32
Just because I pass the argument by a pointer doesn't mean that its wrong. It's also good practice to declare a default constructor and to call it's base class constructor. Why don't you tell me why not?
I did not say that your functions incorrect. I said that they are different functions. And I do not know about your "good practice" of declaring a default constructor and calling a base default constructor when there is no such a need. At least it would be much better if you would define the default constructor of class A as
So far there are two options to solve it.
1). using a class pointer instead as the argument
2). declare the class function first, then define it outside the class definition.