non-aggregate type bool

  • Thread starter Christian Christmann
  • Start date
C

Christian Christmann

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
 
V

Victor Bazarov

Christian said:
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
 
C

Christian Christmann

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.
Your 'bitset->BitSet::data is a pointer. A pointer does not have any
'begin' members. It doesn't have any members.


Because 'data' is of a type that is not a class with a member 'begin'.


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
Chris
 
D

Donovan Rebbechi

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top