Can anyone please look at code and tel what is issue in

Laptop::Laptop(int wdSize, int memSize,int storSize, int spee,int wid, int hei , int len , int wait )
    {
        Computer::Computer(int wdSize, int memSize, int storSize , int spee);

    width=wid;
    length=len;
    height=hei;
    weight=wait;    
} 

Computer::show(); which is a base class member is not being called here.Compute::show() is define in below code. M using cfree boorland 5 compiler.
orignal code is below

#include<iostream.h>
#include<conio.h>
class Computer
{
protected:
int wordSize;
int memorySize;
int storageSize;
int speed;
public: 
Computer(){}
Computer(int,int,int,int);
void show();
};
class Laptop
{
    private:
int width;
int height;
int length;
int weight;

public: 
Laptop(){}
Laptop(int,int,int,int,int,int,int,int);
void show();
};
Computer::Computer(int wdSize, int memSize, int storSize ,int spee)
{
    wordSize=wdSize;
    memorySize=memSize;
    storageSize=storSize;
    speed=spee;
}
void Computer::show()
{
    cout<<"Word Size :"<<wordSize<<endl;
    cout<<"Memory Size: "<<memorySize<<endl;
    cout<<"Storage Size"<<storageSize<<endl;
    cout<<"Speed :"<<speed;
}
Laptop::Laptop(int wdSize, int memSize,int storSize, int spee,int wid, int hei , int len , int wait )
    {
        Computer::Computer(int wdSize, int memSize, int storSize , int spee);

    width=wid;
    length=len;
    height=hei;
    weight=wait;    
} 
void Laptop::show()
{    Computer::show();
    cout<<"weight is="<<weight<<endl;
    cout<<"height is ="<<height<<endl;
    cout<<"length is ="<<length<<endl;
    cout<<"width is ="<<width<<endl;  

}
void main()
{
    clrscr();
    Computer comp(4,512,20,2);
    Laptop lap(8,1024,50,2,15,19,14,2);
    cout<<"Computer Specifications are"<<endl;
    comp.show();
    cout<<":Laptop specifications are"<<endl;
    lap.show();
    getch();
}   

Edited 1 Year Ago by me vicky

I'm not a C++ programmer per se, but a few things struck me as needing to be changed.
I. When you declare your derived class Laptop, you must indicate that it has a base class Computer

class Laptop: public Computer

II. In class Laptop's constructor, when you call the base class's constructor, but don't need the type definitions nor the base class name in the call...

Yours: Computer::Computer(int wdSize, int memSize, int storSize , int spee);

Mine: Computer(wdSize, memSize, storSize, spee);

Those changes solved the problem for me. I'm using Mingw C++, so the results may vary a bit, but not much. Hope that helps.

Cheers!

Edited 1 Year Ago by incomer: Formatting didn't look right

This article has been dead for over six months. Start a new discussion instead.