470,819 Members | 1,591 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

whats wrong with this ? (compilation errors)

typedef struct llist_entry_s llist_entry; /* opaque type */

struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};
Apr 7 '07 #1
8 1421
2b|!2b==? a écrit :
typedef struct llist_entry_s llist_entry; /* opaque type */

struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};
llist_entry() is not a valid member function declaration. Did you mean
llist_entry_s() ?

J.
Apr 7 '07 #2
On Apr 7, 9:40 pm, "2b|!2b==?" <r...@your.box.comwrote:
typedef struct llist_entry_s llist_entry; /* opaque type */
Why the typedef? I'd just write:

class llist_entry ;

(My coding standards say to only use the keyword "class" for
forward declarations.)
struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;
llist_entry() :next(0), keyword(0), value(0)
There are two errors here: first, you didn't specify a return
type for the function, and second, you try to use an initializer
sequence which is only legal in constructors.
{
}
};
--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 7 '07 #3
"2b|!2b==?" <ro**@your.box.comwrote in message
news:Lb******************************@bt.com...
typedef struct llist_entry_s llist_entry; /* opaque type */

struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};
You don't say what compiler errors you get.

The above code compiles successfully for me with VC++.

BTW you don't need that typedef. You could write it
like this:

struct llist_entry
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};

-Mike
Apr 7 '07 #4

"James Kanze" <ja*********@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 7, 9:40 pm, "2b|!2b==?" <r...@your.box.comwrote:
typedef struct llist_entry_s llist_entry; /* opaque type */
Why the typedef? I'd just write:

class llist_entry ;

(My coding standards say to only use the keyword "class" for
forward declarations.)
struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
There are two errors here: first, you didn't specify a return
type for the function,
It's a constructor; no return type.
and second, you try to use an initializer
sequence which is only legal in constructors.
It is a ctor.

-Mike
{
}
};


Apr 7 '07 #5


Mike Wahler wrote:
"2b|!2b==?" <ro**@your.box.comwrote in message
news:Lb******************************@bt.com...
>>typedef struct llist_entry_s llist_entry; /* opaque type */

struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};


You don't say what compiler errors you get.

The above code compiles successfully for me with VC++.

BTW you don't need that typedef. You could write it
like this:

struct llist_entry
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
{
}
};

-Mike
Ah, I'm back now - I needed the break (and some coffee). I sorted this
one out. It was due to the file extension (*.c) - it was expecting C
code - so compiler barfed when it got to the initialization list ...
>
Apr 8 '07 #6
"Mike Wahler" <mk******@mkwahler.netschrieb im Newsbeitrag
news:fI********************@newsread2.news.pas.ear thlink.net...
>
"James Kanze" <ja*********@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 7, 9:40 pm, "2b|!2b==?" <r...@your.box.comwrote:
typedef struct llist_entry_s llist_entry; /* opaque type */
>Why the typedef? I'd just write:

class llist_entry ;

(My coding standards say to only use the keyword "class" for
forward declarations.)
struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;

llist_entry() :next(0), keyword(0), value(0)
>There are two errors here: first, you didn't specify a return
type for the function,

It's a constructor; no return type.
A constructor is a "function" which has the same name as the class (or
struct) it belongs to. Here, the name of the struct is "llist_entry_s" and
the name of the supposed c-tor is "llist_entry". Those names are different
and therefore llist_entry_s::llist_entry() is not a constructor. It doesn't
matter that somewhere else there is a typedef for llist_entry. Any names
declared outside the scope of llist_entry_s may be overwritten by another
declaration inside that scope.

Heinz
Apr 8 '07 #7
On Apr 7, 9:56 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
"James Kanze" <james.ka...@gmail.comwrote in message

news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 7, 9:40 pm, "2b|!2b==?" <r...@your.box.comwrote:
typedef struct llist_entry_s llist_entry; /* opaque type */
Why the typedef? I'd just write:
class llist_entry ;
(My coding standards say to only use the keyword "class" for
forward declarations.)
struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;
llist_entry() :next(0), keyword(0), value(0)
There are two errors here: first, you didn't specify a return
type for the function,
It's a constructor; no return type.
No it's not. A constructor has the same name as the class.
This is apparently an attempt to declare a member function.
and second, you try to use an initializer
sequence which is only legal in constructors.
It is a ctor.
No it's not. That's why he's having problems.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 8 '07 #8
On Apr 7, 9:54 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
"2b|!2b==?" <r...@your.box.comwrote in message
news:Lb******************************@bt.com...
typedef struct llist_entry_s llist_entry; /* opaque type */
struct llist_entry_s
{
llist_entry * next;
char * keyword;
char * value;
llist_entry() :next(0), keyword(0), value(0)
{
}
};
You don't say what compiler errors you get.
The above code compiles successfully for me with VC++.
It shouldn't. G++ says:
ctor.cc:16: error: ISO C++ forbids declaration of 'llist_entry'
with no type
ctor.cc:18: error: declaration of 'int
llist_entry_s::llist_entry()'
ctor.cc:8: error: changes meaning of 'llist_entry' from 'typedef
struct llist_entry_s llist_entry'
ctor.cc: In member function 'int llist_entry_s::llist_entry()':
ctor.cc:16: error: only constructors take base initializers
Which is what I'd expect.
BTW you don't need that typedef. You could write it
like this:
struct llist_entry
{
llist_entry * next;
char * keyword;
char * value;
llist_entry() :next(0), keyword(0), value(0)
{
}
};
That would be more idiomatic C++, of course.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 8 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthew Wilson | last post: by
2 posts views Thread by Tommy Vercetti | last post: by
2 posts views Thread by Phil Certain | last post: by
7 posts views Thread by =?Utf-8?B?UHJpdmF0ZQ==?= | last post: by
1 post views Thread by BSand0764 | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.