Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > non-aggregate type error assistance needed

Reply
Thread Tools

non-aggregate type error assistance needed

 
 
Alden Pierre
Guest
Posts: n/a
 
      04-05-2006
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
 
Reply With Quote
 
 
 
 
Gavin Deane
Guest
Posts: n/a
 
      04-05-2006

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

 
Reply With Quote
 
 
 
 
Alden Pierre
Guest
Posts: n/a
 
      04-05-2006
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
 
Reply With Quote
 
Ben Pope
Guest
Posts: n/a
 
      04-05-2006
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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STL: assistance with error - class undefine type Alden Pierre C++ 7 05-20-2006 06:21 AM
Architectural assistance needed! news.microsoft.com ASP .Net 2 01-13-2006 03:53 PM
Cisco certification FAQ assistance needed www.networking-forum.com Cisco 0 12-17-2005 05:39 PM
FPGA Project assistance needed!! azdunes VHDL 2 09-16-2004 05:17 PM
assistance needed with SAM Cheryl Microsoft Certification 0 06-30-2003 06:35 PM



Advertisments