non-aggregate type bool

Discussion in 'C++' started by Christian Christmann, Mar 25, 2005.

  1. 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
     
    Christian Christmann, Mar 25, 2005
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Mar 25, 2005
    #2
    1. Advertising

  3. >> 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
     
    Christian Christmann, Mar 25, 2005
    #3
  4. On 2005-03-25, Christian Christmann <> 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/
     
    Donovan Rebbechi, Mar 25, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Vilim

    Re: Non Aggregate Type?

    Ryan Vilim, Aug 2, 2003, in forum: C++
    Replies:
    1
    Views:
    4,450
    Artie Gold
    Aug 2, 2003
  2. Kevin Goodsell

    Re: Non Aggregate Type?

    Kevin Goodsell, Aug 2, 2003, in forum: C++
    Replies:
    1
    Views:
    637
    Kevin Goodsell
    Aug 2, 2003
  3. Alden Pierre
    Replies:
    3
    Views:
    366
    Ben Pope
    Apr 5, 2006
  4. Timothee Groleau

    non-aggregate type error?

    Timothee Groleau, Apr 27, 2006, in forum: C++
    Replies:
    2
    Views:
    729
    Timothee Groleau
    Apr 27, 2006
  5. rickman
    Replies:
    5
    Views:
    472
    rickman
    Mar 30, 2013
Loading...

Share This Page