473,326 Members | 2,192 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,326 software developers and data experts.

Union or class hierarchy

Hi
I need to create a class that represent IPv4 and IPv6.
I thought about two options:
1. define an abstract base class, and derive two class, one
implementing IPv4 and the other IPv6.
2. define a class with a union that contain an int32 (for ipv4) and 16
bytes array (for ipv6).

The problem with the first option is that i need to use the 'new' and
'delete' operators every time i need an object (instead just a local
parameter). The second option is not so good also because it waist
space (specially in ipv4 case) and I need to use the 'if' statement in
every function of the class in order to decide what behavior (and
which memeber of the union) to use.

Any other idea for implementation?

Thanks, Yariv
Jul 22 '05 #1
0 986

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stefan Seefeld | last post by:
hi there, I'v run into a little problem for which I only found an ugly workaround, so I'd like to know whether people are aware of better ways to achieve this... I'm defining a class 'Class'...
9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
2
by: Matt | last post by:
Hello, I would like to generate what I call an "overall class hierarchy" in UML automatically derived from my C++ code source. An example of what I seek: ...
15
by: Ken Allen | last post by:
I have some code from C/C++ that I am attempting to port to C#. I have come across an interesting problem that is quite common in complex C/C++ code: the us of UNION in structure definitions to...
4
by: Jeff Mallett | last post by:
VC++.NET gave me Compiler Error C2621, which states, "A union member cannot have a copy constructor." Yikes, that can't be true! As I understand it, *all* class objects have copy constructors,...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
84
by: Peter Olcott | last post by:
Is there anyway of doing this besides making my own string from scratch? union AnyType { std::string String; double Number; };
3
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this...
7
by: Peter Olcott | last post by:
Why can a union have a member with a copy constructor?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.