C++ Polymorphism conversion error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lolcheelol
    New Member
    • Feb 2010
    • 25

    C++ Polymorphism conversion error

    The error I am getting is:

    ERROR E2034 Cannot Convert 'Data 3 *' to 'Gg *' in function main()

    This is my source code, well the stuff that matters I believe. The code is about 500 lines, and I didn't want to flood it, so yeah here you go.

    Code:
    class Data3: public Data2a, public Data2b{
    protected: 
    int *p2;
    int *p3;
    int ct1;
    int forever1;
    public:
    Data3();
    ~Data3();
    void fileInput3();
    void fileOutput();
    }; // data3
    Data3::Data3(){
    p2 = new int[1300];
    p3 = new int[100];
    ct1 = 0;
    forever1 = 1;
    }
    Data3::~Data3(){
    delete p3;
    delete p2;
    }
    
    void Data3::fileInput3(){	
    ifstream in2("nums.dat");
    while(forever1){ 
    in2 >> *(p2+ct1); 
    if(*(p2+ct1) == -1) break;
    ct1++; 
    } 
    in2.close();
    cout << "\n\n\tFile size = " << ct1;
    
    ifstream in3("names.dat");
    for(ct1=0;!in3.eof();++ct1){
    in3>>(s1+ct1)->n1;
    in3>>(s1+ct1)->name1;
    in3>>(s1+ct1)->c1;
    in3>>(s1+ct1)->d1;
    } // FOR
    cout << "\n\n\tFile size = " << ct1;
    }
    
    void Data3::fileOutput(){
    ofstream out1("out2a.dat");
    for(int i=0; i<ct1; i++){
    cout << " " << *(p2+i);
    if((i%15==0)&&(i>0)) cout << "\n";
    if((i%150==0)&&(i>0)){
    cout << "\n\n\tEnter to continue...\n";
    getch();
    } // if
    } // FOR LOOP
    out1.close();
    for(int i=0; i<ct1; i++){
    cout << "\n\t";
    cout << (s1+i)->n1 << " ";
    cout << (s1+i)->name1 << " ";
    cout << (s1+i)->c1 << " ";
    cout << (s1+i)->d1;
    if((i%15==0)&&(i>0)){
    cout << "\n\t";
    cout << "\n\tEnter to continue...";
    getch();
    }
    } // FOR
    }
    
    int main(){
    Data3 *d3;
    d3 = new Data3;
    Gg *g1, *g2, *g3, *g5, *g6 ,*g7 , *g8, *g11;
    g8=new Data3; ////////////////////////////$$$$$$$ << --- the error line
    here is the absolute class, or gg

    Code:
    class Gg{
    	public: 
    		Gg(){cout << "\n\tGg CONSTRUCTOR";}
    		~Gg(){cout<<"\n\tGg DESTRUCTOR";}
    		virtual void inputData()=0;
    		virtual void printData()=0;
    		virtual void getStrings()=0;
    	        virtual void printStrings()=0;
    		virtual void doData()=0;
    		virtual void doMethod()=0;
    		virtual void seeData()=0;
    	   	virtual void showData()=0;
    		virtual void randomData()=0;
    		virtual	void fileInput1()=0;
    		virtual void fileOutput1()=0;
    		virtual	void fileInput2()=0;
    		virtual void fileOutput2()=0;
    		virtual	void fileInput3()=0;
    		virtual void fileOutput()=0;
    };

    any insight on the matter would be greatly appreciated. if you need the rest of the code let me know.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Date3 and Gg appear to be completely different types!
    Further, you need to call a constructor like a function:
    g8=new Data3();

    Comment

    • lolcheelol
      New Member
      • Feb 2010
      • 25

      #3
      I figured it out. Thanks for your help :]

      Comment

      Working...