Error: Constructors Not Allowed A Return Type

T

TheReckter

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

}
 
S

Sumit Rajan

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

}
 
K

Kai-Uwe Bux

TheReckter said:
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
 
T

Tom Smith

Sumit said:
TheReckter said:
I can figure out what is wrong with this piece of code,
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
 
E

Earl Purple

Sumit said:
TheReckter said:
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).
 
S

Serge Paccalin

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).
 
D

Default User

Earl said:
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
 
D

Default User

Default said:
Earl said:
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
 

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,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top