Convert a C++ program?

This is a discussion on Convert a C++ program? within the C Programming forums, part of the General Programming Boards category; Hi, Can someone please convert the following program from C++ to C please...thanks kind regards Atif class PE { public: ...

  1. #1
    unregistered
    Guest

    Convert a C++ program?

    Hi,
    Can someone please convert the following program from C++ to C please...thanks

    kind regards
    Atif


    class PE
    {
    public:
    int OnLockRequest();
    int OnUnLock();
    int OnLockNeeded();
    int OnReceivingDemand();
    int OnRecevingToken();

    private:
    int HasToken();
    PE* NextPE;

    int Lock();
    int UnLock();
    int MoveToken();
    };

  2. #2
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Lightbulb

    How 'bout this?

    typedef struct pe {
    int HasToken();
    struct pe* NextPE;
    }PE;

    int OnLockRequest();
    int OnUnLock();
    int OnLockNeeded();
    int OnReceivingDemand();
    int OnRecevingToken();

    int Lock();
    int UnLock();
    int MoveToken();

    There is no data encapsulation in the data types in C. All functions are universally accessible if they are declared within function-calling scope. Furthermore, all data contained in any structure are also accessible if they are in range.

    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    >>int HasToken();

    struct's aren't allowed to have member functions. That's the advantage of a class. This function will have to be declared outside of the struct.

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >struct's aren't allowed to have member functions.

    Correct. But if you really want to use functions and structs, you can add pointers to functions in the struct and let the pointers to the functions.

  5. #5
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Talking haha...

    Yah sorry my mistake...

    But I was almost perfect wasn't it?
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program to convert numbers into words
    By Kingsley in forum C Programming
    Replies: 5
    Last Post: 07-01-2006, 08:50 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 08:51 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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