Thread: i have some error

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    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--;
    	 
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, what is the specific problem that you are facing?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    i think in overloading
    and i coudn't find the other

  4. #4
    Always learning
    Join Date
    Apr 2009
    Posts
    25
    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?
    Code:
    chapter t=*this;
    You are not using t anywhere...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM