7 drived classes with one common base class

Posted by user144905 on Programmers See other posts from Programmers or by user144905
Published on 2014-08-19T04:19:22Z Indexed on 2014/08/19 4:31 UTC
Read the original article Hit count: 189

Filed under:
|

i have written the following code,

   //main.cpp

#include<iostream>

#include<string>

#include"human.h"

#include"computer.h"

#include"referee.h"

#include"RandomComputer.h"

#include"Avalanche.h"

#include"Bureaucrat.h"

#include"Toolbox.h"

#include"Crescendo.h"

#include"PaperDoll.h"

#include"FistfullODollors.h"

using namespace std;

int main()

{

Avalanche pla1;
Avalanche pla2;

referee f;
pla1.disp();
for (int i=0;i<5;i++)
{


    cout<<pla2.mov[i];
    }

return 0;

}

in this program all included classes except referee.h and human.h are drived from computer.h. each drived calls has a char array variable which is initialized when a member of a drived class is declared.

the problem is that when i declare tow diffrent drived class memebers lets say Avalache and ToolBox. upon printing the char array for one of them using for loop it prints nothing.

However if i declare only one of them in main.cpp the it works properly.

and the file for computer.h is as such:

    #ifndef COMPUTER_H
#define COMPUTER_H
class computer
{
    public:
    int nump;
    char mov[];
    void disp();
};
#endif

ToolBox.h is like this:

    #ifndef TOOLBOX_H

#define TOOLBOX_H

#include"computer.h"

class Toolbox: public computer

{

    public:

    Toolbox();

};

#endif

finally Avalanche.h is as following:

#ifndef AVALANCHE_H

#define AVALANCHE_H

#include"computer.h"

class Avalanche: public computer

{

    public:

    Avalanche();

};

#endif

© Programmers or respective owner

Related posts about c++

Related posts about class