i have some error

This is a discussion on i have some error within the C++ Programming forums, part of the General Programming Boards category; Problem Description: We want to build tool for managing our education. This tool preserves our time and effort. It keeps ...

  1. #1
    c++
    c++ is offline
    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
    21,717
    So, what is the specific problem that you are facing?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    c++
    c++ is offline
    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, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21