Thread: Classes

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    91

    Classes

    if i have one class called Message.cpp
    and then another class called LinkedList.cpp
    and another class called Node.cpp
    and another class called FoundMessage.cpp
    How do i link these together to do the following..

    -> get messages from the Message.cpp class
    -> put the message's info into a Node
    -> The node is then inserted into the linkedlist
    -> in FoundMessage.cpp there is a function that finds a particular message in the linked list.

    assuming that i have all the code .. how would i go about this..
    im not sure how classes relate to each other and if there is any restrictions on calling another class's functions..

    any help?

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    91
    so far im stuck with this happening
    i have a node.h and a node.cpp
    i also have linkedlist.cpp and linkedlist.h
    in linkedlist.cpp im calling a function that is in node.cpp..
    but i am getting this error
    Code:
    LinkedList.cpp:30: error: `makeNode' undeclared (first use this function)
    ??
    in linkedlist.cpp i also have #include "linkedlist.h" and #include "node.h"
    isnt this enough?
    thanks

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Post the code that gives the error.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    just one quick note.. you might already know this.. but you might want to save your classes as .h header files... i.e. message.h

    just be sure to include
    Code:
    #include "message.h"
    along with your preprocessor directives (#include<whatever >) in your driver (.cpp) program.


    then.. compile your .cpp program.. and the header file will automatically be compiled along with your .cpp program.
    Last edited by The Brain; 08-01-2004 at 05:26 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    91
    im just reviewing my code now and it looks like one biggg mess....
    and im just falling into this huge pit of confusion..
    hopefully help is on the way

    ok heres my code

    Code:
    /*   NODE.H    */
    
    class Node {
     public:
            Node();
            ~Node();
            Node* makeNode(const char *s, int a, int b);
    
     private:
            string msg;
            int s;
            int t;
            Node* nextPtr;
    };
    Code:
    /*  NODE.CPP  */
    #include "node.h"
    
    Node * Node::makeNode(const char *s, int a, int b) {
    
            Node * newNodePtr = (Node *)malloc(sizeof(Node));
    
            if(newNodePtr == NULL) {
                    cerr << "Out of memory" << endl;
            }
            else {
                    newNodePtr->msg = s;
                    newNodePtr->t = a;
                    newNodePtr->s = b;
                    newNodePtr->nextPtr = NULL;
            }
            return newNodePtr;
    }
    Code:
    /*   LINKEDLIST.H   */
    
    #include "Node.h"
    
    class LinkedList {
     public:
            LinkedList(LinkedList* listPtr); // constructor
            void Insert(LinkedList* listPtr);
            void insertItem(LinkedList* listPtr, const char * s, int type, int status);
            int deleteNodes(LinkedList* listPtr);
    
     private:
            int count;
            Node* headPtr;
    };
    hopefully you can see from this, im TRYING to implement it so that i have a linked list of nodes.. not sure if that private member Node* headPtr should be LinkedList * headPtr or not...
    i want to be able to do things like..
    Code:
    Node * newNode;
    newNode->headPtr->msg = "hello";
    so im not sure if those declarations and the structure are correct..

    and finally the linkedlist.cpp where makeNode error (and many others) was occuring..

    Code:
    /*   LINKEDLIST.CPP    */ 
    
    #include "LinkedList.h"
    #include "Node.h"
    
    
    void LinkedList::insertItem(LinkedList* listPtr, const char * item, int type, int status) {
    
            Node* newNodePtr = makeNode(item, type, status);
            Node* prevPtr = NULL;
            if (position == 0)
            {
                    newNodePtr->nextPtr = listPtr->headPtr;
                    listPtr->headPtr = newNodePtr;
            }
            else
            {
                    prevPtr = setPosition(listPtr, position-1);
                    newNodePtr->nextPtr = prevPtr->nextPtr;
                    prevPtr->nextPtr = newNodePtr;
            }
            listPtr->count++;
    }

    i know thats heaps of code to take in.. hoep you can help

    THANKS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM