473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vector as a Member Data of a Class

94 New Member
Hi, everyone! If I want a class with a vector data member, can I specify it as follows?

Expand|Select|Wrap|Line Numbers
  1. std::vector< bool > integers( 101 )
I'm having some problems when compiling my code. Thanks in advance!
Dec 30 '13 #1
3 1208
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are probably doing everything correctly.

Here's some C++ dirty laundry: A vector<bool> is not a vector!

Bits in C are usually handled using bitfields. So the vector<bool> uses bitfields, is not a template, has methods not in any real vector, is not an array.

Other than that, it works great (so I hear).

If you insist on bool, then bury the bool in a class and have a vector of that class.
Dec 31 '13 #2
stdq
94 New Member
Actually, I had to initialize the vector in respect to its size using a member intializer. But thanks for the info!
Dec 31 '13 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are wandering into a swamp.

You will find that vector<bool> iterators can't be dereferenced nor an they be incremented.

vector<bool> is not an array so operator[] won't compile.

vector<bool> was a design error in C++ 1998 and is only kept for backwards compatibility. No new code is supposed to be written using this non-standard container.

You are supposed to use bitset<> for managing at the bit level.
Dec 31 '13 #4

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

Similar topics

1
1297
by: roni | last post by:
my target is to create objects only as data member of class. (but offcourse i can pass the objects reference to other objects) my question: how can i make sure that my object is create as data...
1
1519
by: M. Steinbach | last post by:
Thanks. --- class Real { public: double data; }; class A { public:
0
1062
by: M. Steinbach | last post by:
--- class Real { public: double data; }; class A { public: Real a; typeof( a.data ) b; // Fails
11
1670
by: Bob Hairgrove | last post by:
The following class contains start and end points of a range of values. The range can have a direction which is implied from the relative order of start and end, or it can be without direction. IOW...
2
4033
by: Lovens Weche | last post by:
I'm trying to compile this code with VC++ 7: class KeyboardInterface { public: .....
4
1409
by: Steve Kallal | last post by:
I seem to remember that VB 6 had a way to bind a data class redirectly to an ADO recordset. Simply put, a the class could be populated with the recordset data without a lot of coding simply by using...
2
3781
by: Jason | last post by:
Hello: First, if this is one of those "questions asked a million times" just say so and I'll dig a little deeper. If not, then... I'm curious, is it typical to use member data (properties,...
3
1701
by: Curten | last post by:
Hi, I'm a beginner and need help with the following: I have defined a class A where a private data member is an array of structs; private: vector<a_struct> Data; The values of the...
8
1277
by: Verbal Kint | last post by:
Hallo everybody, I am having a short question here which I can not answer myself. The problem is, that I would like to give a vector to a class and modify the vector with the help of the...
3
1860
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data...
0
7231
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
7336
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,...
0
7405
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...
1
7066
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...
1
5059
isladogs
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...
0
4724
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...
0
3214
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
1568
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 ...
1
773
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.