Thread: Code Help

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    Code Help

    Hi im a beginner programmer and i came across this structure and constructor for a book keeping program that i dont understand, could someone plz explain it

    class Book
    {
    public:
    string Title;
    string Author;
    string Publisher;
    int ISBN;
    string Editor;
    float Cost;
    Part* next;
    Part(string, string, string, int, string, float, Book*);
    ~Book();
    private:
    };

    Book::Book(string tempTitle, string tempAuthor, string tempPublisher, int tempISBN, string tempEditor, float tempCost, Part* tempNext):Title(tempTitle), Author(tempAuthor), Publisher(tempPublisher), ISBN(tempISBN), Editor(tempEditor), Cost(tempCost), next(tempNext){}
    Book::~Book(){}

    typedef Book* BookPtr;

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    What part dont you understand? the class itself or the functions and stuff inside. How it works? what does it do? be more clear? you know what constructors do right?
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>could someone plz explain it
    Explain what, exactly?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    i came across this structure and constructor
    although, they are practically the same (only one difference) in c++, you might want to refer to structures and classes by their respective names.

    also, if it is the constructor you have trouble with, look up initializer list...if it has to do with pointers or parameters, you may want to look up those terms as well.

    actually on second look, i don't see any constructors in the class.

    also, use code tags...

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You made a typo when you copied it into your post.

    Code:
    //This part defines a class. anything after "public:"
    //means that you can access those members
    //outside of class instances by using the objects
    //name followed by a dot followed by the
    //encapsulated object's name
    
    class Book 
    { 
    public: 
        string Title; 
        string Author; 
        string Publisher; 
        int ISBN; 
        string Editor; 
        float Cost; 
        Part* next; 
        Book(string, string, string, int, string, float, Book*); // Here was the typo. This is the constructor declaration
        ~Book(); //This is the destructor declaration
    private: 
    };
    
    
    
    //Here is the Book's constructor.
    //When you create an object of type "Book"
    //you have to specify the parameters in this
    //function so that the object is initialized properly.
    //The data after the single colon is the initializer list,
    //which individually initializes each object with the
    //information the user passes when he constructs a Book
    
    Book::Book(string tempTitle, string tempAuthor, string tempPublisher, int tempISBN, string tempEditor, float tempCost, Part* tempNext)
        :    Title(tempTitle), Author(tempAuthor),
             Publisher(tempPublisher), ISBN(tempISBN),
             Editor(tempEditor), Cost(tempCost), next(tempNext)
    {
    }
     
    
    //This is the Book's destructor.
    //Right now, it doesn't do anything.
    //If the book were in charge of dynamically
    //allocating something to be stored within
    //the object, then the destructor would
    //be in charge of deallocating the memory
    
    Book::~Book()
    {
    }
    
    typedef Book* BookPtr; //This says that whenever you use
                                          //the word BookPtr it represents
                                          //the pointer to Book datatype
    If you need more help, refer to this post.
    Last edited by Polymorphic OOP; 01-20-2003 at 06:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM