473,473 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Containing containers - handling interface ?

Hello!

I have something like this:

class A;
Class B;

typedef std::list<A> ContainerA;
typedef std::vector<B> ContainerB;

class C
{
....
private:
ContainerA ac;
ContainerB bc;
}

Class C is not "kind of" ContainerA, nor "kind of" ContainerB. I want to
say, containment is more logical than inheritance (even though, as I've
heard, std containers were not meant to be inherited from, so if only for
that, inheritance is out of question). Now, what really interests me, how
to create good interface of class C? This needs to be accomplished in a way
that some of goodies from ContainerA and ContainerB interface are not lost.

I have two working solutions. First is to put methods into class C
interface that really only return iterators and stuff like that from
ContainerA and ContainerB. For example:

class C
{
public:
typedef ContainerA::iterator iteratorA;
typedef ContainerB::const_iterator const_iteratorA;

iteratorA begin() { return ac.begin(); }
const_iterator_A end() { return ac.end(); }
...// And so on for anything I need.
private:
ContainerA ac;
ContainerB bc;
};

Second would be this:

class C
{
public:
ContainerA ac;
ContainerB bc;
}

From the point of good design which is better? Is this one of the (rare
and mythical) cases where data members should be exposed?
Jul 23 '05 #1
0 1092

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

Similar topics

1
by: Koen | last post by:
Hi! I have a vector containing the following: vector<Base*> theVector; theVector.push_back(new Der1()); theVector.push_back(new Der1()); theVector.push_back(new Der2());...
12
by: Glen Able | last post by:
Hello, I've been getting into the STL lately for personal projects and I'm can't decide whether to wrap containers or not. So the choice is whether to have a member variable like this: ...
4
by: Merlin | last post by:
Hi, I am a C++ developer and would like to implement container classes for various types of objects. I use MS Visual C++ to compile my code. Nevertheless I like to write code that is independent...
13
by: Dylan | last post by:
I'd like to compare two containers. They should be considered equivalent if both containers have the same number of elements with the same values, no matter what order the values are in. For...
8
by: Gregory | last post by:
I have a question about using STL containers in C++ class public interface. Lets say that I want to return some container from class method or accept class method parameter as some container. For...
11
by: jimxoch | last post by:
Hi list, Most STL containers are storing their data on the heap. (although some std::string implementations are notable exceptions) Of course, using the heap as storage increases flexibility and...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
0
by: saneman | last post by:
C++ contains the following containers: - Vector - List - Dequeue - Queue - Stack - Map - Set - Bitset
14
by: Christopher | last post by:
Related to my last post, but seperate question Can a class be made into a container of its self? Could I Create an attribute class representing a name, value pair Create an attributeGroup...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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...
0
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...
0
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...
0
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 ...
0
muto222
php
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.