non-aggregate type error assistance needed

Discussion in 'C++' started by Alden Pierre, Apr 5, 2006.

  1. Alden Pierre

    Alden Pierre Guest

    Hello,

    I'm having a hard time trying to figure why my code will not compile.
    When I try to compile the code, I get the non-aggregate type error. Any
    ideas on what I'm doing wrong?

    ---------------------------------------------------------------------
    File: main.cpp
    ---------------------------------------------------------------------
    #include "roster.h"

    int main( void )
    {
    Roster myRoster();

    for( int i =0; i < 3; i++ ){
    myRoster.addItem();
    }

    myRoster.print();
    return 0;
    }

    -------------------------------------------------------------------------
    File Roster.h
    -------------------------------------------------------------------------
    #ifndef _ROSTER_H_
    #define _ROSTER_H_

    #include "person.h"
    #include "student.h"
    #include "faculty.h"
    #include "admin.h"
    #include <iostream>

    using std::boolalpha;

    struct Node
    {
    Person *p;
    Node *next;
    };

    class Roster
    {
    public:
    Roster();
    ~Roster();
    bool addItem( void );
    bool isEmpty( void );
    void print( void );

    private:
    int Selection();
    void rosterAdd( int );
    Node *head;
    Node *tail;
    };
    #endif

    Regards,
    Alden
    Alden Pierre, Apr 5, 2006
    #1
    1. Advertising

  2. Alden Pierre

    Gavin Deane Guest

    Alden Pierre wrote:
    > Hello,
    >
    > I'm having a hard time trying to figure why my code will not compile.
    > When I try to compile the code, I get the non-aggregate type error. Any
    > ideas on what I'm doing wrong?
    >
    > ---------------------------------------------------------------------
    > File: main.cpp
    > ---------------------------------------------------------------------
    > #include "roster.h"
    >
    > int main( void )
    > {
    > Roster myRoster();


    This line does not do waht you think it does. You are trying to declare
    a variable of type Roster, called myRoster and default-construct it.

    What you've actually done is declared a function called myRoster that
    takes no arguments and returns an object of type Roster. Try

    Roster myRoster;

    >
    > for( int i =0; i < 3; i++ ){
    > myRoster.addItem();
    > }
    >
    > myRoster.print();
    > return 0;
    > }


    <snip>

    Gavin Deane
    Gavin Deane, Apr 5, 2006
    #2
    1. Advertising

  3. Alden Pierre

    Alden Pierre Guest

    Gavin Deane wrote:
    > Alden Pierre wrote:
    >> Hello,
    >>
    >> I'm having a hard time trying to figure why my code will not compile.
    >> When I try to compile the code, I get the non-aggregate type error. Any
    >> ideas on what I'm doing wrong?
    >>
    >> ---------------------------------------------------------------------
    >> File: main.cpp
    >> ---------------------------------------------------------------------
    >> #include "roster.h"
    >>
    >> int main( void )
    >> {
    >> Roster myRoster();

    >
    > This line does not do waht you think it does. You are trying to declare
    > a variable of type Roster, called myRoster and default-construct it.
    >
    > What you've actually done is declared a function called myRoster that
    > takes no arguments and returns an object of type Roster. Try
    >
    > Roster myRoster;
    >
    >> for( int i =0; i < 3; i++ ){
    >> myRoster.addItem();
    >> }
    >>
    >> myRoster.print();
    >> return 0;
    >> }

    >
    > <snip>
    >
    > Gavin Deane
    >

    Thanks for the swift reply it worked. I thought by declaring Roster
    myRoster() the default constructor would get called. :)

    Regards,
    Alden
    Alden Pierre, Apr 5, 2006
    #3
  4. Alden Pierre

    Ben Pope Guest

    Alden Pierre wrote:
    > Thanks for the swift reply it worked. I thought by declaring Roster
    > myRoster() the default constructor would get called. :)


    That's ok, you're not the first person to make that mistake, and you
    won't be the last!

    General rule: If it looks like a function declaration, it probably is.

    Ben Pope
    --
    I'm not just a number. To many, I'm known as a string...
    Ben Pope, Apr 5, 2006
    #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,383
    Artie Gold
    Aug 2, 2003
  2. Kevin Goodsell

    Re: Non Aggregate Type?

    Kevin Goodsell, Aug 2, 2003, in forum: C++
    Replies:
    1
    Views:
    615
    Kevin Goodsell
    Aug 2, 2003
  3. Christian Christmann

    non-aggregate type bool

    Christian Christmann, Mar 25, 2005, in forum: C++
    Replies:
    3
    Views:
    1,742
    Donovan Rebbechi
    Mar 25, 2005
  4. Timothee Groleau

    non-aggregate type error?

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

Share This Page