468,512 Members | 1,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Error: Constructors Not Allowed A Return Type

I can figure out what is wrong with this piece of code, Supposedly
there is an error on line 9 of the following piece of code. If anyone
could help me with this strange issue, the help would be greatly
appreciated, thank you.

#include "stdafx.h"

class WordGenerator
{
public:
WordGenerator(char Format[], int Amount);
}

WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9

}

Oct 9 '06 #1
8 5419
TheReckter wrote:
I can figure out what is wrong with this piece of code, Supposedly
there is an error on line 9 of the following piece of code. If anyone
could help me with this strange issue, the help would be greatly
appreciated, thank you.

#include "stdafx.h"

class WordGenerator
{
public:
WordGenerator(char Format[], int Amount);
}
;

Missing semi-colon.
>
WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9

}
Oct 9 '06 #2
TheReckter wrote:
I can figure out what is wrong with this piece of code, Supposedly
there is an error on line 9 of the following piece of code. If anyone
could help me with this strange issue, the help would be greatly
appreciated, thank you.

#include "stdafx.h"

class WordGenerator
{
public:
WordGenerator(char Format[], int Amount);
}
The line *above* has to end with a ";".
WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9

}
Best

Kai-Uwe Bux
Oct 9 '06 #3
That did it, thankyou both for your help

Oct 9 '06 #4
Sumit Rajan wrote:
TheReckter wrote:
>I can figure out what is wrong with this piece of code,
<snip>
>class WordGenerator
{
public:
WordGenerator(char Format[], int Amount);
}

;

Missing semi-colon.

This is *always* worth looking for when you've got a bizarre error. I'd say
about 20% of my stupid mistakes are caused by this; and the compiler is never
any help. (Actually it just occurred to me that the mistake is probably in the
auto-completed class definition that I use... maybe better check that!)

Tom
Oct 9 '06 #5

Sumit Rajan wrote:
TheReckter wrote:
I can figure out what is wrong with this piece of code, Supposedly
there is an error on line 9 of the following piece of code. If anyone
could help me with this strange issue, the help would be greatly
appreciated, thank you.

#include "stdafx.h"

class WordGenerator
{
public:
WordGenerator(char Format[], int Amount);
}

;

Missing semi-colon.

WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9

}

One of those things that the compiler should be able to work out,
because it's obvious that that } is closing the definition of the
class. Yes, a semi-colon is required (although they might change the
standard someday to make it optional as we could get by easily enough
without it). However the compiler should imagine it there and continue
as though it had been there when it comes to reporting subsequent
errors.

One problem I often have is in a constructor where one of the types is
not correctly defined in the argument parameter list and the compiler
prefers to puzzle me with some other statement, possibly a parse error
(instead of pointing to the keyword that is obviously intended to be a
type).

Oct 9 '06 #6
Le 09.10.2006 17:23, :
One of those things that the compiler should be able to work out,
because it's obvious that that } is closing the definition of the
class. Yes, a semi-colon is required (although they might change the
standard someday to make it optional as we could get by easily enough
without it). However the compiler should imagine it there and continue
as though it had been there when it comes to reporting subsequent
errors.
The compiler can't do that because there are other valid tokens there:

class SomeClass
{
//...
} SomeVar;

is valid, for example.

--
___________
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Pour bien répondre avec Google, ne pas cliquer
-'(__) « Répondre », mais « Afficher les options »,
_/___(_) puis cliquer « Répondre » (parmi les options).
Oct 9 '06 #7
Earl Purple wrote:
>
Sumit Rajan wrote:
Missing semi-colon.
>
WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9
>
}


One of those things that the compiler should be able to work out,
because it's obvious that that } is closing the definition of the
class. Yes, a semi-colon is required (although they might change the
standard someday to make it optional as we could get by easily enough
without it). However the compiler should imagine it there and continue
as though it had been there when it comes to reporting subsequent
errors.
No, it's not obvious. The following is legal:

class a
{
int b;
} func()
{
a A;
return A;
}

Brian

Oct 9 '06 #8
Default User wrote:
Earl Purple wrote:

Sumit Rajan wrote:
Missing semi-colon.
>

WordGenerator::WordGenerator(char Format[], int Amount)
{ //Line 9

}

One of those things that the compiler should be able to work out,
because it's obvious that that } is closing the definition of the
class. Yes, a semi-colon is required (although they might change the
standard someday to make it optional as we could get by easily
enough without it). However the compiler should imagine it there
and continue as though it had been there when it comes to reporting
subsequent errors.

No, it's not obvious. The following is legal:

class a
{
int b;
} func()
{
a A;
return A;
}
Eh. I thought that was ok, and VC took it, but g++ says:

"ISO C++ forbids defining types within return type".
So probably never mind.


Brian
Oct 9 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

42 posts views Thread by Edward Diener | last post: by
1 post views Thread by masood.iqbal | last post: by
4 posts views Thread by Steve Long | last post: by
2 posts views Thread by Don Kim | last post: by
7 posts views Thread by p | last post: by
4 posts views Thread by Adam | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.