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

non-aggregate type bool

Hi,

I'm working on my first STL program. My class BitSet
has three private attributes size, curbit and the STL
bit_vector data which contains some bits.
Here is the code for the constructors:

[snip]
BitSet::BitSet()
:last(-1)
{
std::bit_vector<bool> data (INITSIZE*WORDLEN);
size = INITSIZE;
curbit = 0;
}

BitSet::BitSet(const BitSet &bitset)
:size(bitset.size), curbit(0), last(bitset.last)
{
std::bit_vector<bool> data(size*WORDLEN);

// I try to assing the attribute data of bitset to data
data.assing(bitset.data.begin(), bitset.data.end());
}
[snip]

Compiling the code produces the error message:

bitset.cpp: In copy constructor `BitSet::BitSet(const BitSet&)':
bitset.cpp:82: request for member `begin' in `bitset->BitSet::data', which is
of non-aggregate type `bool*'
bitset.cpp:82: request for member `end' in `bitset->BitSet::data', which is of
non-aggregate type `bool*'

Why can't I access bitset.data.begin() within the constructor?
By the way, is this the correct method to copy the attribute data of
bitset to the new created attribute data?

Thanks
Chris

Jul 23 '05 #1
3 2836
Christian Christmann wrote:
I'm working on my first STL program.
Could it be you're aiming just a tad high with it?
My class BitSet
has three private attributes size, curbit and the STL
bit_vector data which contains some bits.
Here is the code for the constructors:

[snip]
BitSet::BitSet()
:last(-1)
{
std::bit_vector<bool> data (INITSIZE*WORDLEN);
size = INITSIZE;
curbit = 0;
}

BitSet::BitSet(const BitSet &bitset)
:size(bitset.size), curbit(0), last(bitset.last)
{
std::bit_vector<bool> data(size*WORDLEN);

// I try to assing the attribute data of bitset to data
data.assing(bitset.data.begin(), bitset.data.end());
}
[snip]

Compiling the code produces the error message:

bitset.cpp: In copy constructor `BitSet::BitSet(const BitSet&)':
bitset.cpp:82: request for member `begin' in `bitset->BitSet::data', which is
of non-aggregate type `bool*'
bitset.cpp:82: request for member `end' in `bitset->BitSet::data', which is of
non-aggregate type `bool*'
Your 'bitset->BitSet::data is a pointer. A pointer does not have any
'begin' members. It doesn't have any members.
Why can't I access bitset.data.begin() within the constructor?
Because 'data' is of a type that is not a class with a member 'begin'.
By the way, is this the correct method to copy the attribute data of
bitset to the new created attribute data?


How would we know without seeing the class definition? Have you tried
using 'std::copy'?

V
Jul 23 '05 #2
>> I'm working on my first STL program.

Could it be you're aiming just a tad high with it?
Probably you are right ;)
But unfortunately I have to finish this project.

bitset.cpp: In copy constructor `BitSet::BitSet(const BitSet&)':
bitset.cpp:82: request for member `begin' in `bitset->BitSet::data',
which is
of non-aggregate type `bool*'
bitset.cpp:82: request for member `end' in `bitset->BitSet::data', which
is of
non-aggregate type `bool*'


Your 'bitset->BitSet::data is a pointer. A pointer does not have any
'begin' members. It doesn't have any members.
Why can't I access bitset.data.begin() within the constructor?


Because 'data' is of a type that is not a class with a member 'begin'.
By the way, is this the correct method to copy the attribute data of
bitset to the new created attribute data?


How would we know without seeing the class definition? Have you tried
using 'std::copy'?

No, not yet. But will try it next.

My class definition:

[snip]

class BitSet
{
private :
bool *data;
int size;
int curbit;
int last;

public :
BitSet();
BitSet(const BitSet &bitset);

[snip]

Thanks
V

Chris

Jul 23 '05 #3
On 2005-03-25, Christian Christmann <pl*****@yahoo.de> wrote:
Hi,

I'm working on my first STL program. My class BitSet
has three private attributes size, curbit and the STL
bit_vector data which contains some bits.
Here is the code for the constructors:

[snip]
BitSet::BitSet()
:last(-1)
{
std::bit_vector<bool> data (INITSIZE*WORDLEN);
This constructs a temporary variable called 'data', it doesn't initialize
the class member variable called 'data'.

Anyway, use initialization lists -- for all of your variables.
BitSet::BitSet(const BitSet &bitset)
:size(bitset.size), curbit(0), last(bitset.last)
{
std::bit_vector<bool> data(size*WORDLEN);
see above
// I try to assing the attribute data of bitset to data
data.assing(bitset.data.begin(), bitset.data.end());
bitset.data is of type bool*, it doesn't have a member called begin (or
end or any other member. It's just a dumb pointer)
Why can't I access bitset.data.begin() within the constructor?
By the way, is this the correct method to copy the attribute data of
bitset to the new created attribute data?


As long as your class doesn't dynamically allocate, the compiler generated
copy constructor (which just initialises all the fields with the fields of
its argument) will do just fine.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #4

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
22
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
13
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.