cant find the error

i am not able to understand the compilation error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
class A
{
      protected:
                int a,b;
                public:
                       A(int x,int y)
                       {
                             a=x;
                             b=y;
                             }
                             virtual void print();
};
class B:public A
{
      private:
              float p,q;
              public:
                     B(float u,float v)
                     {
                           p=u;
                           q=v;
                     }
                     B()
                     {
                          p=q=0;
                     }
                     void input(float u,float v);
                     virtual void print(float);
};
void A::print(void)
{
     cout<<"A values:"<<a<<""<<b<<"\n";
}
void B::print(float)
{     
     cout<<"B values:"<<p<<""<<q<<"\n";
     }
     void B::input(float x,float y)
     {
          p=x;
          q=y;
          }
          int main()
          {
              A a1(10,20),*ptr;
              B b1;
              b1.input(7.5,3.142);
              ptr=&a1;
              ptr->print();
              ptr=&b1;
              ptr->print();
              system("pause");
              }     
                                   

error:
In constructor `B::B(float, float)':
no matching function for call to `A::A()'
candidates are: A::A(const A&)
A::A(int, int)
In constructor `B::B()':
no matching function for call to `A::A()'
candidates are: A::A(const A&)
A::A(int, int)
Last edited on
It would be helpful to inlude error you get in your oist. And use code tags. They looks like <> on the right of the edit field.

By the way this is invalid: A(int x=0,int y) What you think =0 is doing here?
B derives from A. Therefore, B must know how to construct that part of itself which is A. Your constructor for B must therefore pass the required arguments to the constructor for A. To do this, you must use an initializer list.

Since you haven't used an initializer list, the compiler assumes that you want the constructor for B to call the default constructor for A. The compiler is reporting that you haven't defined such a constructor.
Topic archived. No new replies allowed.