By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

non-aggregate type bool

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
>> 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.