Thread: Pointer to class

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    69

    Pointer to class

    Hello, I need interaction between classes and I do it this way:

    Code:
    class tcp_packet
    {
        private:
    
        public:
            int *from;
        .....
    };
    
    class con_client
    {
        private :
            int sock;
        public :
            DWORD ServeClient();
            ....
    };
    
    ........
    
    DWORD con_client::ServeClient()
    {
    ...
    cResult =  recv(this->sock, (char*)RecPck.buff, 1024, 0);
            if (cResult > 0)
            {
                RecPck.size = cResult;
                RecPck.from = (int*)this;
            }
    ...
    }
    
    void tcp_packet_s_handler::read_Login(tcp_packet pck)
    {
        con_client *c;
        c = (con_client*)pck.from;
    }
    But it doesnt work, whats wrong there?

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    how do you propose to convert the data in that packet into an address of an instance of your con client class?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. base class pointer pointing at derived class
    By mynickmynick in forum C++ Programming
    Replies: 11
    Last Post: 12-01-2008, 12:26 PM
  2. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  3. Replies: 25
    Last Post: 10-29-2007, 04:08 PM
  4. finding derived class type of a pointer to a base class
    By LinuxCoder in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2006, 11:08 AM
  5. base class pointer to derived class objects
    By curlious in forum C++ Programming
    Replies: 4
    Last Post: 09-28-2003, 08:39 PM