NEWBIE: Class Problem

This is a discussion on NEWBIE: Class Problem within the C++ Programming forums, part of the General Programming Boards category; I can't seem to get this working. It gives me 2 syntax errors (under visual C++ 6) saying that im ...

  1. #1
    Registered User jimboob's Avatar
    Join Date
    Jun 2004

    Question NEWBIE: Class Problem

    I can't seem to get this working. It gives me 2 syntax errors (under visual C++ 6) saying that im missing ';' on line 43. Can someone please tell me what ive done wrong?
    #include <iostream.h>
    class Network
    	// Handles the Server
    	void MT_StartServer(int *Port);
    	void MT_EndServer(int *Port);
    	// Handles the Client
    	void MT_ConnectToServer(int *Port);
    	void MT_DisconnecFromServer(int *Port);
    	// Handles Input/Output
    	void MT_SendMessage(char *Message);
    	void MT_ReceiveMessage(char *Message);
    	// Private Ints
    	int Port;		// The Port as of which they'll be using
    	// Private Chars
    	char Message[50];// The message they'll be sending
    void Network::MT_StartServer(int *Port)
    	cout << Port;
    int main()
    	Network.MT_StartServer(1299); // This is line 43
    	return 0;
    Last edited by Salem; 06-25-2004 at 06:48 AM. Reason: [code][/code] tags added - please remember

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well for a start, your MT_StartServer() expects a pointer to an int, and gets an int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Next off, you don't actually have an instance of your class any place, and since that isn't a static member function, you can't just call that function by itself.

    Hope is the first step on the road to disappointment.

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    your member functions arn't static.
    You can't call non static methods from the class itself, you need to instantiate a class.
    Network nwVariable;
    Network *nwVariable = new Network();


    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >your member functions arn't static.
    It still wouldn't work even if they were, unless the OP is using some bastardization of C with Classes and C++. To access a static member function, you use the scope resolution operator, not the member operator:
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  2. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  5. Class Include Problem (I Think)
    By gpr1me in forum C++ Programming
    Replies: 8
    Last Post: 03-21-2006, 11:47 AM

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