Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 6th, 2006, 02:25 AM
Gary Wessle
Guest
 
Posts: n/a
Default compile error

Hi

I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of ‘Account’ with no type

I cannot find out why. can you please help?

thanks

// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"

class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H

//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account {
public:
Account();
// ~Account();
};

#endif // ACCOUNT_H

  #2  
Old December 6th, 2006, 02:35 AM
Daniel T.
Guest
 
Posts: n/a
Default Re: compile error

In article <m3d56x3fik.fsf@localhost.localdomain>,
Gary Wessle <phddas@yahoo.comwrote:
Quote:
Hi
>
I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of ‘Account’ with no type
>
I cannot find out why. can you please help?
I don't see anything especially wrong with what you posted. Could it be
that your "Account.h" has a line like: #include "User.h" ?
Quote:
// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"
>
class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H
>
//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
>
class Account {
public:
Account();
// ~Account();
};
>
#endif // ACCOUNT_H
--
To send me email, put "sheltie" in the subject.
  #3  
Old December 6th, 2006, 03:45 AM
Salt_Peter
Guest
 
Posts: n/a
Default Re: compile error


Gary Wessle wrote:
Quote:
Hi
>
I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of 'Account' with no type
>
I cannot find out why. can you please help?
>
thanks
>
// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"
>
class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H
>
//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
>
class Account {
public:
Account();
// ~Account();
};
>
#endif // ACCOUNT_H
In order for the compiler to successfully generate any of the above
class types, you need to implement those 2 def ctors since you've
overriden the compiler's ability to generate and implement them for
you. Hence the error.

So:

// User.cpp
#include "User.h"

User::User()
{
}

Account* User::getAccountWithId(const int accId)
{
return 0; // for now
}

// Account.cpp
#include "Account.h"

Account::Account()
{
}

And in the case you need User::getAccountWithId(...) to respect
constant-correctness, and depending on the container employed, use a
const reference instead:

const Account& User::getAccount(const int accId) const
{
return vacc.at(accId); // vector of accounts or whatever
}

If you prefer for some unknown reason to do it with dumb pointers, at
least protect the returned pointer:

Account* const User::getAccount(const int accId) const
{
return 0; // for now
}

  #4  
Old December 6th, 2006, 04:15 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: compile error


"Gary Wessle" <phddas@yahoo.comwrote in message
news:m3d56x3fik.fsf@localhost.localdomain...
Quote:
Hi
>
I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of 'Account' with no type
>
I cannot find out why. can you please help?
>
thanks
>
// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"
>
class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H
>
//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
>
class Account {
public:
Account();
Where's the body? Either you need a
Account::Account() { /* ... */ }
somewhere, or change this to
Account() {};
Quote:
// ~Account();
};
>
#endif // ACCOUNT_H
>

  #5  
Old December 6th, 2006, 01:35 PM
Pete Becker
Guest
 
Posts: n/a
Default Re: compile error

Gary Wessle wrote:
Quote:
Hi
>
I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of ‘Account’ with no type
>
I cannot find out why. can you please help?
>
thanks
>
// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"
>
class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H
>
//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
>
class Account {
public:
Account();
// ~Account();
};
>
#endif // ACCOUNT_H
>
Both headers compile fine for me, as they ought to. The problem must be
in the code that you didn't show. (Despite two responses saying it, you
don't need to have definitions for any of these members in order to
compile these headers)

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
  #6  
Old December 6th, 2006, 01:45 PM
Pete Becker
Guest
 
Posts: n/a
Default Re: compile error

Jim Langston wrote:
Quote:
"Gary Wessle" <phddas@yahoo.comwrote in message
news:m3d56x3fik.fsf@localhost.localdomain...
Quote:
>Hi
>>
>I am getting many similar compile errors which look like this
>User.h:9: error: ISO C++ forbids declaration of 'Account' with no type
>>
>I cannot find out why. can you please help?
>>
>thanks
>>
>// User.h
>#ifndef USER_H
>#define USER_H
>#include "Account.h"
>>
>class User{
>public:
> User();
> // ~User();
> Account* getAccountWithId(const int accId); //line 9
>};
>#endif // USER_H
>>
>//Account.h
>#ifndef ACCOUNT_H
>#define ACCOUNT_H
>>
>class Account {
>public:
> Account();
>
Where's the body?
In a source file somewhere, presumably. You don't need bodies for member
functions in order to compile a class definition. C++ isn't Java.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
  #7  
Old December 6th, 2006, 04:05 PM
JE
Guest
 
Posts: n/a
Default Re: compile error


Gary Wessle wrote:
Quote:
Hi
>
I am getting many similar compile errors which look like this
User.h:9: error: ISO C++ forbids declaration of 'Account' with no type
>
I cannot find out why. can you please help?
>
thanks
>
// User.h
#ifndef USER_H
#define USER_H
#include "Account.h"
>
class User{
public:
User();
// ~User();
Account* getAccountWithId(const int accId); //line 9
};
#endif // USER_H
>
//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
>
class Account {
public:
Account();
// ~Account();
};
>
#endif // ACCOUNT_H
You may have a typo (e.g. #ifdef ACCOUNT_H).

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles