简体   繁体   中英

Passing array as argument in Parameterized Constructor

I am trying to overload the >> operator to rotate the elements in the array.I have removed the array declaration and initialization for shorten the code. But compiler is giving error as "invalid use of undefined type 'class ABC'." and many more.

#include<iostream>
using namespace std;
class ABC
{
      int iarr[10],n2,n3;
      char carr[10];

      Public:
             ABC();
      ABC(int arr[],char car[],int n,int n1)
      {
              n2=n; n3=n1;
              for(int i=0;i<n;i++)
              iarr[i]=arr[i];
              for(int i=0;i<n1;i++)
                      carr[i]=car[i];
      }

      ABC operator>>(int n)
      {
          while(n)
          {
                  int temp;
                  temp=iarr[n2-1];
                  for(int i=n2-1;i>=0;i--)
                  {
                      iarr[i]=iarr[i-1];
                  }
                  iarr[0]=temp;
          }
      }

      void display()
      {
          for(int i=0;i<n2;i++)
              printf("%d\t",iarr[i]);
          printf("\n");
          for(int i=0;i<n3;i++)
              printf("%d\t",carr[i]);
      }
};

main()
{
    ABC A;
    A=ABC(arr,car,n,n1);
    A.display();
}

Your error " invalid use of undefined type 'class ABC' " is because of your default constructor. You have declared a default constructor, but you have not defined it.

Instead of ABC(); you need to atleast do ABC() {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM