473,795 Members | 3,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Struct within Struct, able to change inner Struct type

84 New Member
There isn't much explaining to this, this is what I have:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     public struct PACKET_HEADER
  3.     {
  4.         public string computerIp;
  5.         public string computerName;
  6.         public string computerCustomName;
  7.     };
  8.  
  9.     public struct PACKET
  10.     {
  11.         public PACKET_HEADER pktHdr;
  12.         public PACKET_DATA pktData;
  13.     };
  14.  
  15.  
  16.     public struct PACKET_DATA
  17.     {
  18.         public Command command;
  19.         public string data;  
  20.     };
  21.  
  22.     public struct DATA_MESSAGE
  23.     {
  24.         public string message;
  25.     };
  26.  
  27.     public struct DATA_FILE
  28.     {
  29.         public string fileName;
  30.         public long fileSize;       
  31.     };
  32.  
Basically I want the data field in PACKET_DATA to be able to be either DATA_FILE or DATA_MESSAGE. I know the type needs to be changed but I don't know what to, is generics an option?

the end result should be so that I can do either:

pktData.data.fi leName
or
pktData.data.me ssage
Dec 20 '10 #1
1 1428
metalheadstorm
84 New Member
Solved please see: http://stackoverflow.com/questions/4...er-struct-type
Dec 20 '10 #2

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

Similar topics

3
10717
by: DraguVaso | last post by:
Hi, How do you change the Startup Type of a Windows Service with VB.NET? When using the ServiceController you can Start and Stop a Service, but I can't find anywhere how to change the Startup Type? Thanks a lot in advance, Pieter
11
4975
by: Keith Wilby | last post by:
A97. I want to be able to use code to open change the data type of a field in a table in another database - can this be done? Many thanks. Keith.
3
3606
by: Serve Laurijssen | last post by:
Given this structure: typedef struct S { struct Inner { char desc; char *file; } *libs; } S;
15
2049
by: dutchgoldtony | last post by:
Hi all, I was just wondering if this is possible. I'm trying to implement a viterbi decoder in C and am creating an array of nodes (the struct), and an array of pointers to nodes (the member I'm worried about) connecting to it like so: // snippet start typedef struct _node{ char state; // The state of each node ("00","01","10","11")
2
2229
by: Walter Deodiaus | last post by:
I have typedef struct { union _union{ .... struct { int i; }u1; .... }Union; } Struct ;
5
4356
by: Johs32 | last post by:
I have a struct "my_struct" and a function that as argument takes a pointer to this struct: struct my_struct{ struct my_struct *new; }; void my_func(struct my_struct *new); I have read that there is no difference between giving this function a
45
18908
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies of their elements? Why can't I change the element itself? class Program { private struct MyStruct
2
2756
by: ice88 | last post by:
i have problem in define struct within struct struct student_detail { int id; string name; }; struct subject_detail
0
1316
by: zman77 | last post by:
Hi. In C dll, there is a struct that contains an array of struct pointers. I do not know how to represent that in C#. That's my problem. Here is the relevant C code: struct vector { uint elem_count; uint size; int (*cmp)(const void *, const void *);
5
7235
by: emmanuel.rivoire | last post by:
Hello, I spent almost a week to be able to embed Python within my C++ game engine. I wrote a mini-tutorial of what I was able to do so far here : http://forums.indiegamer.com/showpost.php?p=169352&postcount=9 At the end of my tutorial, I wrote : "You can do the same with C++ classes, and with structures within structures. Swig can parse & wrap most C/C++ declarations."
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.