i want to set a class back to its original structure after calling a receive function. code below to explain -
class Node
-
{
-
public:
-
Node(){}
-
~Node(){}
-
};
-
-
-
class lol : public Node
-
{
-
public:
-
string strName;
-
};
-
-
class face
-
{
-
public:
-
-
void vSetLOL( CONST Node &C_lol )
-
{
-
this->C_lol = C_lol;
-
}
-
-
const Node getLoL( void ) const
-
{
-
return C_lol;
-
}
-
-
priavte:
-
-
Node C_lol ;
-
}
-
-
-
main
-
{
-
lol C_lol;
-
face C_face;
-
-
C_lol.strname = "gums";
-
-
C_face.vSetLOL( C_lol );
-
-
C_lol.strname = " monkey";
-
-
-
////// how do you change the node C_lol back to lol C_lol /////
-
C_lol = C_face.getLOL(); /// this is the main problem
-
-
}
6 1331
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.
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.
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. -
//// class called Data
-
Data::Data()
-
{
-
char *pcPacket = new char;
-
}
-
-
void Data::setPacketData( const char* pcPacketData )
-
{
-
*pcPacket = *pcPacketData;
-
}
-
-
void Data::getPacketData( const char* pcPacketData )
-
{
-
*pcPacketData = *pcPacket;
-
}
-
-
int main
-
{
-
stucture vector3
-
{
-
int x,y, z;
-
};
-
-
Data C_Data;
-
vector3 vec3;
-
-
/// this would work
-
C_Data.setPacketData( (char*)&vec3 );
-
-
/// this would not work, the returned data would not change?
-
C_Data.getPacketData( (char*)&vec3 );
-
-
return 0;
-
}
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?
oops found the problem, such amateur mistake, im only coping over one byte of data. someone slap me
*SLAP*!
Oops, message too short... *SLAP* *SLAP* *SLAP* ;-)
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. - //////////// this would be done on both sides of the server and the client
-
#define BUFFERSIZE 80
-
-
struct PacketData
-
{
-
float x,y,z;
-
-
}S_PacketData;
-
-
struct Data
-
{
-
char *pcPacket;
-
char *cpName;
-
}S_Data;
-
-
S_Data.pcPacket = new char[ sizeof(PacketData) ];
-
S_Data.cpName = NULL;
-
-
char *NetPacket = new char[ sizeof(PacketData) + BUFFERSIZE ];
-
-
//////////////////////////////////////////////////////////////////////////////////////
-
-
//////// then on the client side it would do this to send information ////////////////
-
-
S_PacketData.x = 5.0f;
-
S_PacketData.y = 15.0f;
-
S_PacketData.z = 25.0f;
-
-
S_Data.cpName = "lols";
-
-
memcpy( S_Data.pcPacket, &S_PacketData, sizeof(PacketData) );
-
-
memcpy( NetPacket, &S_Data, sizeof(PacketData) + BUFFERSIZE );
-
-
send(s, NetPacket, sizeof(PacketData) + BUFFERSIZE,0);
-
-
-
///////////// on the server would have this ///////////////////
-
-
recv (s, NetPacket, sizeof(PacketData) + BUFFERSIZE,0);
-
-
/////// is this correct so far? /////////////////////////////////
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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");...
|
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,...
|
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...
|
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...
|
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...
|
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(
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |