[prog] Re: C++

dominik.schramm at gmxpro.net dominik.schramm at gmxpro.net
Sun Mar 14 19:12:12 EST 2004


Hi,

wolf <wolf at wolfrising.net> writes:

> [...]
> here are the error messages:
> Compiling...
> cd.cpp:20: error: return type specification for constructor invalid

The contructor must have an *empty* type specification, not "void".
See below.

> cd.cpp:29: error: `void cd::showCD()' and `void cd::showCD()' cannot be
>     overloaded

See below: the function signatures are the same (thus overloading is
impossible) but the compiler sees this function twice, once in a declaration,
then in a declaration plus implementation.

> cd.cpp:109: error: parse error at end of input

Don't know about this. Maybe the missing semicolon? (see below)

> this is line 20:
> 20         void cd (string sartist, string stitle, string sgenre, int

Leave away "void", should be:
                  cd (string sartist, ...)

> [...]
> here's the current version of the program:
> #include <iostream>
> using namespace std;
>
> class cd {
> 
> [...]
> 	
> private:
>      cd(string artist, string title, string genre, int year);
>      void showCD();

This is the declaration for the showCD function.

> [...]
> 	void showCD() {
>      // print a cd object
>      cout << artist << " " << genre << " " << title << " " << year <<
>      endl;
> }

This is another (!) declaration plus implementation of showCD. Since the signature
is the same in both cases, the compiler complains that you cannot do overloading
this way. 

BTW. It's confusing to implement member functions inside the class declaration, 
I'd do this outside the class declaration, using names like cd::showCD etc.
I think the above error is an example of such confusion.

> [...]
> void readCDLibrary(cd cdLibrary, int length) {
>      string input, artist, title, genre;
>      int year;
> 	
>      // Open the file ?	
>      for (int i = 0; i < length; i++) {
>          inputstream >> input;
> 		
>          // artist, title, genre, year
> 		
>          cdLibrary[i] = new cd(artist, title, genre, year);
>      }
> }

AFAIK there should be a ; after the class declaration.


hope this helps,
regards,
dominik

-- 
Dominik Schramm <dominik.schramm at gmxpro.net>
pgp key via http://www.cam.ac.uk.pgp.net/pgpnet/wwwkeys.html



More information about the Programming mailing list