-
i have some error
Problem Description:
We want to build tool for managing our education. This tool preserves our time and
effort. It keeps all books (that we study) with their chapters (you do not know how many
chapters that the book may have). For each book, name of book and provided course name
must be saved. If the student studied full chapter, the number of chapters will be decreased.
Code:
#include<iostream>
using namespace std;
class chapter
{
int size;
int *ptr;
public:
chapter(int size=10)
{
ptr=new int[size];
for(int i=0;i<size;i++)
ptr[i]=0;
}
bool chapterread(int f)
{for(int i=0;i<f;i++)
ptr[i]=1;
if(f)
return true;
else
return false;
}
int operator--(int)
{
chapter t=*this;
for(int i=0;i<size;i++)
{
if(chapterread(i)==true)
--size;
}
return size;
}
};
class book
{
private:
string booknamme;
chapter obj;
public:
book(string n,int s):obj(s)
{
booknamme=n;
}
void print()
{cout<<"book name::"<<booknamme<<endl;
cout<<"number of chapter"<<obj.size;
}
};
int main()
{
book b("c++",6);
chapter ch(6);
ch.chapterread(2);
ch--;
}
-
So, what is the specific problem that you are facing?
-
i think in overloading
and i coudn't find the other
-
You have two syntax errors. One of them has to do with something you (probably) forgot to do, the other has to do with something you're not allowed to do.
Even with those errors fixed, there's a segmentation fault that is triggered when you do ch--;
However, the fault is not in that function, but in a different one.
Finally, why this?
You are not using t anywhere...