472,950 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

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 5637
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
4
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is...
2
by: Don Kim | last post by:
When I try to compile the following from the ECMA Docs: #using <mscorlib.dll> using namespace System; public value class point { int Xor; int Yor; public:
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
4
by: Adam | last post by:
Okay, so I know this will come off as a stupid question...but I am going to ask it anyways... I know you are not allowed to have constructors defined in an interface, but why not? I really...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.