3 Replies - 408 Views - Last Post: 23 July 2010 - 01:38 PM Rate Topic: -----

#1 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Question on Pointers and Classes

Posted 23 July 2010 - 01:14 PM

Double posted topic. Please lock.
Thanks!

This post has been edited by ReclusiveManiac: 23 July 2010 - 01:18 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Question on Pointers and Classes

#2 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: Question on Pointers and Classes

Posted 23 July 2010 - 01:14 PM

Hey guys just had a quick question about pointers and classes.


char buffer[128];
Player *p_PlayerOne;
p_PlayerOne = buffer[0];

recv(socketOne, buffer, sizeof(buffer), 0)




If Player is a class and the buffer sent to the program is filled with a Player class, should p_PlayerOne then get all the values of the Player class that was just sent? I'm in the process of testing this right now but just thought I would see if someone could tell off of the top of their head first.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Question on Pointers and Classes

Posted 23 July 2010 - 01:24 PM

First of all, this is wrong:
p_PlayerOne = buffer[0];

Here you are assigning a char to a Player*. Unless you have overloaded assignment operator for Player to do something with the char, it gives you error(which I don't think you had this in mind).

If you explain more about what this buffer contains it would be much easier to talk about it. Does this buffer contain binary data of Player classes?

This post has been edited by Anarion: 23 July 2010 - 01:25 PM

Was This Post Helpful? 0
  • +
  • -

#4 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: Question on Pointers and Classes

Posted 23 July 2010 - 01:38 PM

View PostAnarion, on 23 July 2010 - 12:24 PM, said:

First of all, this is wrong:
p_PlayerOne = buffer[0];

Here you are assigning a char to a Player*. Unless you have overloaded assignment operator for Player to do something with the char, it gives you error(which I don't think you had this in mind).

If you explain more about what this buffer contains it would be much easier to talk about it. Does this buffer contain binary data of Player classes?


Thanks for the reply!

the incoming buffer would have this.


char buffer[128];
Player *p_PlayerOne;
p_PlayerOne = new (buffer) Player;




The Player class would have a constructor to automatically fill in most of the members.

Again thanks for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1