hello,
I have following problem:
I have a struct "MainStruct "
now I want to build structs which all "starts" with MainStruct.
struct1
{
MainStruct var;
anotherStruct var2;
}
struct2
{
MainStruct var;
AnotherStruct2 var2;
}
......is there a way to do this?
And how can I declare a method, which accepts all structs which a derived
from MainStruct as argument?
I hope you have understood all (I'm from Germany) 5 2599
> I have a struct "MainStruct " now I want to build structs which all "starts" with MainStruct.
struct1 { MainStruct var; anotherStruct var2; }
struct2 { MainStruct var; AnotherStruct2 var2; }
.....is there a way to do this? And how can I declare a method, which accepts all structs which a derived from MainStruct as argument?
It doesn't work this way. You could reach what you want using inheritance
but structs doesn't support inheritance you should use a class instead.
I hope you have understood all (I'm from Germany)
Ich denk' schon :)
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
lol....sind doch ganz schön viele deutsche drin:-)
hatt ich schon oft
"codymanix" <do************ *********@gmx.d e> schrieb im Newsbeitrag
news:#w******** ******@TK2MSFTN GP12.phx.gbl... I have a struct "MainStruct " now I want to build structs which all "starts" with MainStruct.
struct1 { MainStruct var; anotherStruct var2; }
struct2 { MainStruct var; AnotherStruct2 var2; }
.....is there a way to do this? And how can I declare a method, which accepts all structs which a
derived from MainStruct as argument?
It doesn't work this way. You could reach what you want using inheritance but structs doesn't support inheritance you should use a class instead.
I hope you have understood all (I'm from Germany)
Ich denk' schon :)
-- cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
but when I do:
struct1
{
....
}
struct2 : struct1
{
newMember;
}
where in memory are the new mebers?
behind the members of struct1 or in front of it?
this is, because its a class I use to P/Invoke a Win32 call.
I need it so:
MembersOfBaseCl ass
MembersOfDerive dClass
"Dirk Reske" <_F*******@gmx. net> schrieb im Newsbeitrag
news:eD******** ******@TK2MSFTN GP12.phx.gbl... lol....sind doch ganz schön viele deutsche drin:-) hatt ich schon oft
"codymanix" <do************ *********@gmx.d e> schrieb im Newsbeitrag news:#w******** ******@TK2MSFTN GP12.phx.gbl... I have a struct "MainStruct " now I want to build structs which all "starts" with MainStruct.
struct1 { MainStruct var; anotherStruct var2; }
struct2 { MainStruct var; AnotherStruct2 var2; }
.....is there a way to do this? And how can I declare a method, which accepts all structs which a derived from MainStruct as argument?
It doesn't work this way. You could reach what you want using
inheritance but structs doesn't support inheritance you should use a class instead.
I hope you have understood all (I'm from Germany)
Ich denk' schon :)
-- cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
> lol....sind doch ganz schön viele deutsche drin:-) hatt ich schon oft
Liegt auch einfach daran das die deutschen newsgroups zum kotzen sind. Wenn
du keinen Realname verwendest, deine Rechtschreibung nicht perfekt ist oder
was auch immer, dann wirs du gleich dumm angemacht.
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
The new members are always behind the the members of the base-class in
memory but as already pointed out you have to use classes, not structs.
The exact position and alignment of the members in memory are not defined
and should not be of interest for you.
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
"Dirk Reske" <_F*******@gmx. net> schrieb im Newsbeitrag
news:uD******** ******@TK2MSFTN GP11.phx.gbl... but when I do:
struct1 { ... }
struct2 : struct1 { newMember; }
where in memory are the new mebers? behind the members of struct1 or in front of it? this is, because its a class I use to P/Invoke a Win32 call. I need it so:
MembersOfBaseCl ass MembersOfDerive dClass
"Dirk Reske" <_F*******@gmx. net> schrieb im Newsbeitrag news:eD******** ******@TK2MSFTN GP12.phx.gbl... lol....sind doch ganz schön viele deutsche drin:-) hatt ich schon oft
"codymanix" <do************ *********@gmx.d e> schrieb im Newsbeitrag news:#w******** ******@TK2MSFTN GP12.phx.gbl... > I have a struct "MainStruct " > now I want to build structs which all "starts" with MainStruct. > > struct1 > { > MainStruct var; > anotherStruct var2; > } > > struct2 > { > MainStruct var; > AnotherStruct2 var2; > } > > .....is there a way to do this? > And how can I declare a method, which accepts all structs which a derived > from MainStruct as argument?
It doesn't work this way. You could reach what you want using inheritance but structs doesn't support inheritance you should use a class
instead. > I hope you have understood all (I'm from Germany)
Ich denk' schon :)
-- cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian F |
last post by:
Hi, I'm a C-newbie and I would like to know if I am doing something
wrong in the code below. It is working, but I'm afraid it might not be
correct because I don't really understand everything of it. There are
lots of pointers and pointers to pointers which makes me confused.
First my typedef:
typedef struct
{
double re;
|
by: stephen henry |
last post by:
Hi all,
I have a question that I'm having difficulty answering. If I have a
struct:
typedef struct my_struct_tag{
struct my_other_struct *other;
} my_struct_tag
|
by: Paminu |
last post by:
Why make an array of pointers to structs, when it is possible to just make
an array of structs?
I have this struct:
struct test {
int a;
int b;
|
by: pinkfloydhomer |
last post by:
Is it well-defined and portable to do something like:
typedef struct
{
int type;
char c;
} S1;
typedef struct
{
|
by: Marty |
last post by:
I am new to C# and to structs so this could be easy or just not
possible.
I have a struct defined called Branch
If I use Branch myBranch = new Branch(i); // everything works
If I use Branch (myBranch + x) = new Branch(i); // it doesn't
x is a loop iterator, i is an int for the constructor to define an
array.
What am I doing wrong here.
| |
by: Johan Tibell |
last post by:
Could someone outline the pros and cons of typedefing pointers to
structs like this?
typedef struct exp_ {
int val;
struct exp_ *child;
} *exp;
(This is straight from memory so it might not even compile.)
|
by: jason |
last post by:
In the microsoft starter kit Time Tracker application, the data access
layer code consist of three cs files.
DataAccessHelper.cs
DataAcess.cs
SQLDataAccessLayer.cs
DataAcccessHelper appears to be checking that the correct data type is
used
DataAcess sets an abstract class and methods
|
by: emin.shopper |
last post by:
I had a need recently to check if my subclasses properly implemented
the desired interface and wished that I could use something like an
abstract base class in python. After reading up on metaclass magic, I
wrote the following module. It is mainly useful as a light weight tool
to help programmers catch mistakes at definition time (e.g., forgetting
to implement a method required by the given interface). This is handy
when unit tests or...
|
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,...
|
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...
|
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...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |