Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error: request for member of non-class type

Reply
Thread Tools

error: request for member of non-class type

 
 
Andre
Guest
Posts: n/a
 
      11-18-2007
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;
}
#####################################
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      11-18-2007
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
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      11-18-2007

"Andre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
> }
> #####################################



 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-18-2007
On Nov 18, 3:22 am, Kai-Uwe Bux <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      11-18-2007
James Kanze wrote:

> On Nov 18, 3:22 am, Kai-Uwe Bux <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sharing: member type deduction for member pointers (Alf's device?) Alf P. Steinbach /Usenet C++ 4 07-19-2010 08:21 AM
Sharing: member type deduction for member pointers (Alf's device?) Alf P. Steinbach /Usenet Python 4 07-19-2010 08:21 AM
Accessing a protected member of a member of type BaseClass???? Steven T. Hatton C++ 2 08-16-2004 03:11 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments