473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

to pass in a unknown data and retrieving it

i want to set a class back to its original structure after calling a receive function. code below to explain

Expand|Select|Wrap|Line Numbers
  1. class Node
  2. {
  3.     public:
  4.     Node(){}
  5.     ~Node(){}
  6. };
  7.  
  8.  
  9. class lol  : public Node
  10. {
  11.     public:
  12.     string strName;
  13. };
  14.  
  15. class face
  16. {
  17.     public:
  18.  
  19.     void vSetLOL( CONST Node &C_lol )
  20.     {
  21.         this->C_lol  = C_lol;
  22.     }
  23.  
  24.     const Node getLoL( void ) const
  25.     {
  26.         return C_lol;
  27.     }
  28.  
  29.     priavte:
  30.  
  31.     Node C_lol ;    
  32. }
  33.  
  34.  
  35. main
  36. {
  37.     lol  C_lol;
  38.     face C_face;
  39.  
  40.     C_lol.strname = "gums";
  41.  
  42.     C_face.vSetLOL( C_lol );
  43.  
  44.     C_lol.strname = " monkey";
  45.  
  46.  
  47.     ////// how do you change the node C_lol back to lol C_lol /////
  48.     C_lol = C_face.getLOL();  /// this is the main problem
  49.  
  50. }
Nov 17 '08 #1
6 1331
Ganon11
3,652 Expert 2GB
You may be able to cast C_face.getLOL() to a C_lol, or have the face class hold a lol object instead of a Node object.
Nov 17 '08 #2
Banfa
9,065 Expert Mod 8TB
The bottom line is that you can't. As soon as you copied a class lol to a class Node the value of any data members held in the lol were lost forever.

You may be able to write a constructor and operator= for lol that will take a Node & as the parameter but you will never be able to reconstruct any data held in lol.
Nov 18 '08 #3
Thanks for the replies and sorry about the bad naming in the last example

would that be the same problem if put a structure into a buffer.

Expand|Select|Wrap|Line Numbers
  1. //// class called Data
  2. Data::Data()
  3. {
  4.     char *pcPacket = new char;
  5. }
  6.  
  7. void Data::setPacketData( const char* pcPacketData )
  8. {
  9.     *pcPacket = *pcPacketData;
  10. }
  11.  
  12. void Data::getPacketData( const char* pcPacketData )
  13. {
  14.     *pcPacketData = *pcPacket;
  15. }
  16.  
  17. int main
  18. {
  19.      stucture vector3
  20.      {
  21.           int x,y, z;
  22.      };
  23.  
  24.      Data C_Data;
  25.      vector3 vec3;
  26.  
  27.       /// this would work
  28.      C_Data.setPacketData( (char*)&vec3 );    
  29.  
  30.       /// this would not work, the returned data would not change?
  31.       C_Data.getPacketData( (char*)&vec3 );    
  32.  
  33.      return 0;
  34. }
so the returned data would be impossible to change or is there a mystic way? if was integers or floats that was put into the buffer, i know that would work but not with structures

when i allocate the pcPacket, i should put it into an array, depending on the size of the structure that was sent right?
Nov 18 '08 #4
oops found the problem, such amateur mistake, im only coping over one byte of data. someone slap me
Nov 18 '08 #5
arnaudk
424 256MB
*SLAP*!
Oops, message too short... *SLAP* *SLAP* *SLAP* ;-)
Nov 18 '08 #6
lol ok, new prob, will actually it not a problem yet.

I would just some comments back to see what i'm doing is correct.


Expand|Select|Wrap|Line Numbers
  1. //////////// this would be done on both sides of the server and the client
  2. #define BUFFERSIZE 80
  3.  
  4. struct PacketData
  5. {
  6.     float x,y,z;
  7.  
  8. }S_PacketData;
  9.  
  10. struct Data
  11. {
  12.     char *pcPacket;
  13.     char *cpName;
  14. }S_Data;
  15.  
  16. S_Data.pcPacket = new char[ sizeof(PacketData) ];
  17. S_Data.cpName = NULL;
  18.  
  19. char *NetPacket = new char[ sizeof(PacketData) + BUFFERSIZE ];
  20.  
  21. //////////////////////////////////////////////////////////////////////////////////////
  22.  
  23. //////// then on the client side it would do this to send information ////////////////
  24.  
  25. S_PacketData.x = 5.0f;
  26. S_PacketData.y = 15.0f;
  27. S_PacketData.z = 25.0f;
  28.  
  29. S_Data.cpName = "lols";
  30.  
  31. memcpy( S_Data.pcPacket, &S_PacketData, sizeof(PacketData) );
  32.  
  33. memcpy( NetPacket, &S_Data, sizeof(PacketData) + BUFFERSIZE );
  34.  
  35. send(s, NetPacket, sizeof(PacketData) + BUFFERSIZE,0);
  36.  
  37.  
  38. ///////////// on the server would have this ///////////////////
  39.  
  40. recv (s, NetPacket, sizeof(PacketData) + BUFFERSIZE,0);
  41.  
  42. /////// is this correct so far? /////////////////////////////////
Nov 18 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Christoph | last post by:
For retrieving CSS rules that can not be interpreted by an layout engine I can use the UnknownRule interface of DOM. Unfortunately in Gecko (Firefox 1.0.5), I cannot access such rules using...
1
by: timandsuzi36 | last post by:
Here's the issue. Appreciate any help any Access gurus can offer. I have a .NET WinForms application that needs to launch a Access DB application used for generating Access Reports. That part...
0
by: Padgett | last post by:
Hi There, I'm trying to do an XML / XLS transform but am having trouble retrieving my data. The trouble seems to be with the parameter - if I hard code the id in the template SQL, everything...
10
by: ndm | last post by:
Hi, Just wondering if any one knows a way to pass and enumerate an unknown number of parameter to a VB function. I want to create a Min/Max functions that can: a) take an variable number of...
5
by: DrPete | last post by:
Hi How do you go about passing values to methods if you don't know what the values datatype is? For example: myParm = sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar, 30, "Name");...
0
by: Nico Grubert | last post by:
Hi there, I am trying to open an https site and pass a request to it in order to simulate the submit of an HTML form on a https site that sets an authentication cookie for a tomcat application,...
1
by: bjlemaire | last post by:
Hello, I am writing an app that is retrieving data via an ODBC connection to an Access database. I am returning many columns, and it seems that for certain columns that I try to read, I get the...
2
by: Philip Daniels | last post by:
I am doing some work with a client API via COM interop. I have reached the situation where after this call to their API: object someObj = con.Peek(1); "someObj" contains some type of COM...
2
by: Beacherboy | last post by:
Hi All, This one is a bit complex, so I'll try to be as logical explaining the issue as humanily possible. ASP/VBScript/MySQL Issue: Creating dynamic variables while there is an unknown...
2
by: krishnasamy | last post by:
Hi, I have writing the code in my Dll as follows, //declare the bufferdata BYTE bufferData; //retrieving the picture from the dll prResponse prSTDCALL MyViewFinderFunction(
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.