non-aggregate type error assistance needed

A

Alden Pierre

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
 
G

Gavin Deane

Alden said:
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
 
A

Alden Pierre

Gavin said:
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;


<snip>

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

Regards,
Alden
 
B

Ben Pope

Alden said:
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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top