Thread View: comp.unix.programmer
5 messages
5 total messages
Started by Alan Leung
Fri, 17 Jan 1997 00:00
return type specification for constructor invalid
Author: Alan Leung
Date: Fri, 17 Jan 1997 00:00
Date: Fri, 17 Jan 1997 00:00
59 lines
2057 bytes
2057 bytes
I am trying to compile something relatively simple on my newly installed Linux
OS and I am unable to.
The beginning of my HTMLAppearance.cc file is like:
#include <iostream.h>
#include <assert.h>
#include "HTMLAppearance.h"
// const int MAX_STR_LEN = 20;
#define MAX_STR_LEN 20
HTMLAppearance:: HTMLAppearance( const String filename ) {
ifstream infile(filename);
The beginning of my HTMLAppearance.h file is:
typedef char* String;
class HTMLAppearance {
public:
HTMLAppearance( const String filename );
I issued the command "g++ -Wall -ansi -c HTMLAppearance.cc" on the command
line and received the following error from the compiler:
return type specification for constructor invalid
for the line
HTMLAppearance:: HTMLAppearance( const String filename ) {
in my .cc file. Other errors followed, e.g.
'ifstream' undeclared ( // etc.
for the next line, that are likely the result of the first error.
Just to be sure it was not my compiler, I compiled some older programs
and these compiled correctly. Somewhere there is a little syntax error and
I was hoping a different set of eyes could see through to it.
Please help :-) Thanks.
--
@@@@@@@@@@ Alan Leung, aleung@gpu.srv.ualberta.ca | Comp Sci @@@@@@@@@@
@@ http://www.ualberta.ca/~aleung/distract.html @@
@@@ WWW page subjects incl: Gong Li, Bruce Lee, Aliens-based CGI game @@
@@@ 'The Long Kiss Goodnight' ***** out of 5 @@
Re: return type specification for constructor invalid
Author: Per Madsen
Date: Fri, 17 Jan 1997 00:00
Date: Fri, 17 Jan 1997 00:00
82 lines
2703 bytes
2703 bytes
aleung@scapa.cs.ualberta.ca (Alan Leung) writes:
>
>
> I am trying to compile something relatively simple on my newly installed Linux
> OS and I am unable to.
>
>
> The beginning of my HTMLAppearance.cc file is like:
>
> #include <iostream.h>
> #include <assert.h>
>
> #include "HTMLAppearance.h"
>
> // const int MAX_STR_LEN = 20;
>
> #define MAX_STR_LEN 20
>
> HTMLAppearance:: HTMLAppearance( const String filename ) {
>
> ifstream infile(filename);
>
>
> The beginning of my HTMLAppearance.h file is:
>
> typedef char* String;
>
> class HTMLAppearance {
> public:
> HTMLAppearance( const String filename );
>
>
> I issued the command "g++ -Wall -ansi -c HTMLAppearance.cc" on the command
> line and received the following error from the compiler:
>
> return type specification for constructor invalid
>
> for the line
>
> HTMLAppearance:: HTMLAppearance( const String filename ) {
>
> in my .cc file. Other errors followed, e.g.
>
> 'ifstream' undeclared ( // etc.
>
> for the next line, that are likely the result of the first error.
>
> Just to be sure it was not my compiler, I compiled some older programs
> and these compiled correctly. Somewhere there is a little syntax error and
> I was hoping a different set of eyes could see through to it.
> Please help :-) Thanks.
>
>
>
>
Make sure you end your class definition with a semicolon.
e.g
class Foo
{
...
};
Madsen
--
*-----------------------------------*-----------------------------------*
| Per Madsen | Aalborg Universitet: |
| Sigrid Undsetsvej 248A | Fredrik Bajersvej 7 |
| 9220 Aalborg � | Semester: F7D |
| Tlf: 98153104 | Lokale: C1-213 |
| E-mail: madsen@nork.auc.dk | E-mail: madsen@cs.auc.dk |
| | WWW: www.cs.auc.dk/~madsen |
*----------------------------oooooOOOOOooooo----------------------------*
Re: return type specification for constructor invalid
Author: Brian S St. Pierre
Date: Fri, 17 Jan 1997 00:00
Date: Fri, 17 Jan 1997 00:00
40 lines
1567 bytes
1567 bytes
In article <xytsp40tmrr.fsf@spock.cs.auc.dk>, Per Madsen wrote:
>aleung@scapa.cs.ualberta.ca (Alan Leung) writes:
>
>> The beginning of my HTMLAppearance.cc file is like:
>>
>> #include <iostream.h>
#include <fstream.h>
The file streams are declared separately from the iostreams. Make sure
that you first include iostream.h, then fstream.h
>> #include <assert.h>
>>
>> #include "HTMLAppearance.h"
>>
>> // const int MAX_STR_LEN = 20;
>>
>> #define MAX_STR_LEN 20
>>
>> HTMLAppearance:: HTMLAppearance( const String filename ) {
>>
>> ifstream infile(filename);
>>
Make sure that this function DOES NOT return a value!
>>
>> The beginning of my HTMLAppearance.h file is:
>>
[snip]
>
>Make sure you end your class definition with a semicolon.
--
Brian St. Pierre "Madness takes its toll...
Computer Sci. / Business Admin. Please have exact change."
University of New Hampshire
bss1@kepler.unh.edu
Re: return type specification for constructor invalid
Author: Greg Comeau
Date: Fri, 17 Jan 1997 00:00
Date: Fri, 17 Jan 1997 00:00
67 lines
2673 bytes
2673 bytes
In article <5bnn6t$m9l@scapa.cs.ualberta.ca> aleung@scapa.cs.ualberta.ca (Alan Leung) writes:
>
>I am trying to compile something relatively simple on my newly installed Linux
>OS and I am unable to.
>
>
>The beginning of my HTMLAppearance.cc file is like:
>
>#include <iostream.h>
>#include <assert.h>
>
>#include "HTMLAppearance.h"
>
>// const int MAX_STR_LEN = 20;
>
>#define MAX_STR_LEN 20
>
>HTMLAppearance:: HTMLAppearance( const String filename ) {
>
> ifstream infile(filename);
>
>
>The beginning of my HTMLAppearance.h file is:
>
>typedef char* String;
>
>class HTMLAppearance {
> public:
> HTMLAppearance( const String filename );
>
>
>I issued the command "g++ -Wall -ansi -c HTMLAppearance.cc" on the command
>line and received the following error from the compiler:
>
> return type specification for constructor invalid
>
>for the line
>
> HTMLAppearance:: HTMLAppearance( const String filename ) {
>
>in my .cc file. Other errors followed, e.g.
>
> 'ifstream' undeclared ( // etc.
>
>for the next line, that are likely the result of the first error.
>
> Just to be sure it was not my compiler, I compiled some older programs
>and these compiled correctly. Somewhere there is a little syntax error and
>I was hoping a different set of eyes could see through to it.
> Please help :-) Thanks.
You don't show all your code, but I'll bet that as you
#include ....h in the .c file just before the ctor definition,
that the class decl does not end in a semicolon.
This is a common error. A supporting clue to this is that
for some reason you decided to comment out MAX_STR_LEN
so apparently you were getting an error for that first,
so as that is now a macro (put it back) it just went to the
next "real" line of code.
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
Re: return type specification for constructor invalid
Author: Greg Comeau
Date: Fri, 24 Jan 1997 00:00
Date: Fri, 24 Jan 1997 00:00
39 lines
2141 bytes
2141 bytes
In article <m820bbi5yc.fsf@slbh08.bln.sel.alcatel.de> prange@bln.sel.alcatel.de writes:
>
>I issued the command "g++ -Wall -ansi -c HTMLAppearance.cc" on the command
>>line and received the following error from the compiler:
>>
>> return type specification for constructor invalid
>>
>>for the line
>>
>> HTMLAppearance:: HTMLAppearance( const String filename ) {
>>
>
>This is actually fun to see _three_ people responding and not
>seeing that the problem is on the follwing line ( which has been
>quoted also several times )
>
>HTMLAppearance:: HTMLAppearance( const String filename ) {
>
>which should read:
>
>HTMLAppearance::HTMLAppearance( const String filename ) {
From what I can see, you have only removed a space.
Indeed, that makes no difference, or shouldn't, unless you
have a broken C++ compiler. Something else _is_ wrong.
Since he defined his constructor outside the class,
more than likely he left off the semicolon after the closing
} of the class and hence it got taken as the return type of the ctor,
which is not allowed. There are actually 2 errors then:
(1) A ctor cannot return a value
(2) A type cannot be defined when specifying a return type
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads