By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

please help with decrypting g++'s error-messages

P: n/a
I'm a newbie in the world of c++, and I am used to learn a programming
language simply by programming. Unfortunately I where unable to find
any useful helpfile for this language, in which such basic things as
"class", "operator ::", or even my compiler's error-messages would
get explained in a quick-reference kind of way (as turbo pascal did
with the pascal-language). Therefore I was forced to read some books
and tutorials. However, I'm too lazy to do any exercises, and therefore
I'm stuck in the error-message jungle without a clue of what the compiler
does expect from me.

Does anyone know of some good manual on gcc's error-messages?

Try to compile with some recent gnu c++ compiler:
#include <string>
#include <list>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

class Song;
class Song::File;
//error: no type named "File" in "struct Song"
//error: forward declaration of "struct File"
class PlayList:public list<class Song> {
friend class Song;
protected:
typedef hash_map<string, class Song::File> Hmap;
//error: no type named "File" in struct "Song"
static Hmap fileset;
} /*playlist*/;

class Song {
friend class PlayList;
protected:
class File {
int size;
const std::string songName;
File(std::string s):songName(s){}
};
class PlayList::iterator next;
PlayList::Hmap::iterator fil;
//...instantiated from here:
//error: "std::pair<_T1,_T2>::second" has incomplete type
PlayList* parent;
};

int main (void){
//tests://TODO:add some tests for memory-leakage!
//1) con- and de-structor at stack
{
PlayList p1();
// std::cout<<p1<<std::endl;
}
//1) con- and de-structor in heap
PlayList* p2=new PlayList();
// std::cout<<*p2<<std::endl;
delete p2;
}

--
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...

P
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Piotr Sawuk wrote:
I'm a newbie in the world of c++, and I am used to learn a programming
language simply by programming. Unfortunately I where unable to find
any useful helpfile for this language, in which such basic things as
"class", "operator ::", or even my compiler's error-messages would
get explained in a quick-reference kind of way (as turbo pascal did
with the pascal-language). Therefore I was forced to read some books
and tutorials. However, I'm too lazy to do any exercises, and therefore
I'm stuck in the error-message jungle without a clue of what the compiler
does expect from me.
I am not going to comment on this preamble. OK, just one comment:
are we supposed to sympathise with you after you said that you're
too lazy to do exercises and therefore stuck? If not, why did you
want us to know that?
Does anyone know of some good manual on gcc's error-messages?
Perhaps somebody in gnu.g++.help does...
Try to compile with some recent gnu c++ compiler:
#include <string>
#include <list>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

class Song;
class Song::File;
//error: no type named "File" in "struct Song"
Forward-declaring a member (in your case Song::File) is not
allowed in standard C++. I don't know if that exists in G++
as an extension (nor do I really care). I am not sure where
you got the idea that you may do that [successfully].
//error: forward declaration of "struct File"
Exactly.
class PlayList:public list<class Song> {
friend class Song;
protected:
typedef hash_map<string, class Song::File> Hmap;
//error: no type named "File" in struct "Song"
static Hmap fileset;
} /*playlist*/;

class Song {
friend class PlayList;
protected:
class File {
int size;
const std::string songName;
File(std::string s):songName(s){}
};
class PlayList::iterator next;
PlayList::Hmap::iterator fil;
//...instantiated from here:
//error: "std::pair<_T1,_T2>::second" has incomplete type
Well, I am not sure why it complains about ..::second, since it
is just Song::File and by now it has been fully defined, but the
compiler may just be getting confused by the previous errors.
PlayList* parent;
};

int main (void){
//tests://TODO:add some tests for memory-leakage!
//1) con- and de-structor at stack
{
PlayList p1();
That's a declaration of a function. Lose the parentheses
if you want to create a local object of type 'PlayList'.
// std::cout<<p1<<std::endl;
}
//1) con- and de-structor in heap
PlayList* p2=new PlayList();
// std::cout<<*p2<<std::endl;
delete p2;
}


You're trying to bite off more than you can chew apparently.
Circular references involving derivation and templates are not
for faint-hearted even if they do have some experience behind
their belt. Often, when one tries to involve members of forward-
declared classes to resolve the circular referneces, there is
no hope altogether because the language at this time does NOT
support forward declarations of members.

You might want to think of pulling Song::File type out of Song
and let it live outside, and define it before the first use in
the PlayList class. There is probably more in the books you've
so kindly mentioned.

Victor
Jul 22 '05 #2

P: n/a
I didn't get an answer in a week, maybe I should try again:

In article <cj*********@gander.coarse.univie.ac.at>,
pi****@unet.univie.ac.at (Piotr Sawuk) writes:
I'm a newbie in the world of c++, and I am used to learn a programming
language simply by programming. Unfortunately I where unable to find
any useful helpfile for this language, in which such basic things as
"class", "operator ::", or even my compiler's error-messages would
get explained in a quick-reference kind of way (as turbo pascal did
with the pascal-language). Therefore I was forced to read some books
and tutorials. However, I'm too lazy to do any exercises, and therefore
I'm stuck in the error-message jungle without a clue of what the compiler
does expect from me.

Does anyone know of some good manual on gcc's error-messages?

Try to compile with some recent gnu c++ compiler:

#include <string>
#include <list>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

class Song;
class Song::File;
//error: no type named "File" in "struct Song"
//error: forward declaration of "struct File"
class PlayList:public list<class Song> {
friend class Song;
protected:
typedef hash_map<string, class Song::File> Hmap;
//error: no type named "File" in struct "Song"
static Hmap fileset;
} /*playlist*/;

class Song {
friend class PlayList;
protected:
class File {
int size;
const std::string songName;
File(std::string s):songName(s){}
};
class PlayList::iterator next;
PlayList::Hmap::iterator fil;
//...instantiated from here:
//error: "std::pair<_T1,_T2>::second" has incomplete type
PlayList* parent;
};

int main (void){
//tests://TODO:add some tests for memory-leakage!
//1) con- and de-structor at stack
{
PlayList p1();
// std::cout<<p1<<std::endl;
}
//1) con- and de-structor in heap
PlayList* p2=new PlayList();
// std::cout<<*p2<<std::endl;
delete p2;
}

Can anyone help me with getting above program to run?
What I wish to accomplish is storing the same object in
a list as well as in a hash_map, so that duplicate objects
get found and referenced quickly. For that purpose I need
an iterator into the list stored in the hash-map and an iterator
to the hash-map stored in the list. How to resolve such a
circular declaration-dependency without switching to pointers?
--
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...

P
Jul 22 '05 #3

P: n/a
Piotr Sawuk wrote:
I didn't get an answer in a week, maybe I should try again:

In article <cj*********@gander.coarse.univie.ac.at>,
pi****@unet.univie.ac.at (Piotr Sawuk) writes:
I'm a newbie in the world of c++, and I am used to learn a programming
language simply by programming. Unfortunately I where unable to find
any useful helpfile for this language, in which such basic things as
"class", "operator ::", or even my compiler's error-messages would
get explained in a quick-reference kind of way (as turbo pascal did
with the pascal-language). Therefore I was forced to read some books
and tutorials. However, I'm too lazy to do any exercises, and therefore
I'm stuck in the error-message jungle without a clue of what the compiler
does expect from me.

Does anyone know of some good manual on gcc's error-messages?

Try to compile with some recent gnu c++ compiler:


#include <string>
#include <list>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;


news://gnu.g++.help should of help,
since this seems to be dependent on a
particular implementation.

--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '
Jul 22 '05 #4

P: n/a
Piotr Sawuk wrote:
class Song::File;


You can't declare members of partially declared classes.
The rest of your errors cascade from this declaration.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.