1

Run the code to see where the problem lies.

[Error] 'd' does not name a type

I tried declaring the variable directly in public but it kept popping up with more errors.

There seems to be apparently no fix, since googling didn't help much in the process.

It'd be super helpful if someone could help me figure out where the problem is.

#include<iostream>
using namespace std;

class array1{
    protected:
        static int a[50];
    public:
        int n1;
        void getNum1(void)
        {
            cout<<"how many numbers?"<<endl;
            cin>>n1;
            for(int i=0;i<n1;i++)
            {
                cout<<"enter le number"<<endl;
                cin>>a[i];
            }
        }

        int* retNum1(void)
        {
            return a;
        }
};

class array2{
    protected:
        static int b[50];
    public:
        int n2;
        void getNum2(void)
        {
            cout<<"how many numbers?"<<endl;
            cin>>n2;
            for(int i=0;i<n2;i++)
            {
                cout<<"enter le number"<<endl;
                cin>>b[i];
            }
        }

        int* retNum2(void)
        {
            return b;
        }
};

class conarray:public array1, public array2{
    private:
        int c[100],d;
        //int d;
    public:
        d=0;
        void disp()
        {
            for(int i=0;i<5;i++)
            {
                cin>>c[i];
            }
            for(int i=0;i<5;i++)
            {
                cout<<c[i]<<endl;
            }
            cout<<d;
        }
        //int d = 0;
        /*void merge(void)
        {
            int *nn1 = retNum1();
            int *nn2 = retNum2();
            for(int i=0;i<n1;i++)
            {
                c[d]=nn1[i];
                d++;
            }
            for(int i=0;i<n2;i++)
            {
                c[d]=nn2[i];
                d++;
            }
        }
        void display(void)
        {
            cout<<"NUMBERS IN ARRAY:"<<endl;
            for(int i=0;i<d;i++)
            {
                cout<<c[i]<<endl;
            }
        }*/

};

int main()
{
    conarray a;
    //a.getNum1();
    //a.getNum2();
    //a.merge();
    //a.display();
    a.disp();
    return 0;
}
Ankan Das
  • 268
  • 1
  • 2
  • 11
  • 1
    `d=0` should be within function body. – TruthSeeker Feb 14 '20 at 05:36
  • 1
    `d=0` is an initialization. Try putting that in the constructor – Eduardo Pascual Aseff Feb 14 '20 at 05:36
  • 1
    "Run the code to see where the problem lies." No. You please describe it and provide any correponding information (e.g. error message) directly. Including to identify any line referenced by compile time messages (errors/warnings). By the way, running is impossible if there is a compiler error. – Yunnosch Feb 14 '20 at 05:54
  • @EduardoPascualAseff If you phrase that without a "try" you can turn that into a decent answer. (Ideally test your solution yourself, then skipping the "try" should not be a problem.) – Yunnosch Feb 14 '20 at 06:00
  • Why do you have 2 identical classes `array1` and `array2`, kind of defeats the purpose of classes. – Lukas-T Feb 14 '20 at 06:07

0 Answers0