Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error: request for member of non-class type

604 views
Skip to first unread message

Andre

unread,
Nov 17, 2007, 8:59:25 PM11/17/07
to
Hi all,

Can someone point out what is wrong with this tiny piece of code? I'm
compiling it with "g++ ./Main.cpp", and get the error message "error:
request for member 'konnect' in 'theSocket', which is of non-class
type 'Socket ()()'"

Thanks in advance,

Andre
#####################################
class Socket
{
public:
void konnect(){};
};

int main(int argc, char ** argv)
{
Socket theSocket();

theSocket.konnect();

return 0;
}
#####################################

Kai-Uwe Bux

unread,
Nov 17, 2007, 9:22:33 PM11/17/07
to
Andre wrote:

> Hi all,
>
> Can someone point out what is wrong with this tiny piece of code? I'm
> compiling it with "g++ ./Main.cpp", and get the error message "error:
> request for member 'konnect' in 'theSocket', which is of non-class
> type 'Socket ()()'"

The error message is surprisingly accurate.

> Thanks in advance,
>
> Andre
> #####################################
> class Socket
> {
> public:
> void konnect(){};
> };
>
> int main(int argc, char ** argv)
> {
> Socket theSocket();

This declares theSocket as an uninitialized variable of function type:

Socket () ( void )


You might want to say

Socket theSocket;

instead.

>
> theSocket.konnect();

A function has no members.

>
> return 0;
> }
> #####################################


Best

Kai-Uwe Bux

Jim Langston

unread,
Nov 17, 2007, 10:53:45 PM11/17/07
to

"Andre" <sieg...@yahoo.com> wrote in message
news:816a2eeb-67ad-4157...@b40g2000prf.googlegroups.com...

> Hi all,
>
> Can someone point out what is wrong with this tiny piece of code? I'm
> compiling it with "g++ ./Main.cpp", and get the error message "error:
> request for member 'konnect' in 'theSocket', which is of non-class
> type 'Socket ()()'"
>
> Thanks in advance,
>
> Andre
> #####################################
> class Socket
> {
> public:
> void konnect(){};
> };
>
> int main(int argc, char ** argv)
> {
> Socket theSocket();

Here you declare a function called "theSocket" taking no parameters and
returning an instance of Socket. Not what you wanted. Change this line to:
Socket theSocket;

and all should be well. In C++ if something can be interpreted as a
function prototype, it is.

> theSocket.konnect();
>
> return 0;
> }
> #####################################


James Kanze

unread,
Nov 18, 2007, 6:32:54 AM11/18/07
to
On Nov 18, 3:22 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> Andre wrote:

[...]


> > int main(int argc, char ** argv)
> > {
> > Socket theSocket();

> This declares theSocket as an uninitialized variable of function type:

Variables of function type don't exist. This declares theSocket
as an external function. (I'm pretty sure that this is what you
meant, but talking about a variable of function type sounds
strange, at least to me.)

--
James Kanze (GABI Software) email:james...@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

Kai-Uwe Bux

unread,
Nov 18, 2007, 7:07:46 AM11/18/07
to
James Kanze wrote:

> On Nov 18, 3:22 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
>> Andre wrote:
>
> [...]
>> > int main(int argc, char ** argv)
>> > {
>> > Socket theSocket();
>
>> This declares theSocket as an uninitialized variable of function type:
>
> Variables of function type don't exist. This declares theSocket
> as an external function.

Right.

> (I'm pretty sure that this is what you
> meant, but talking about a variable of function type sounds
> strange, at least to me.)

Your interpretation is too charitable :-)

I was just goofing off.


Thanks

Kai-Uwe Bux

0 new messages