473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 5649
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.