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

P

Piotr Sawuk

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;
}
 
V

Victor Bazarov

Piotr said:
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
 
P

Piotr Sawuk

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

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?
 
K

Karthik Kumar

Piotr said:
I didn't get an answer in a week, maybe I should try again:



#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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,178
Messages
2,570,955
Members
47,509
Latest member
Jack116

Latest Threads

Top