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;
}
#####################################
> 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
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;
> }
> #####################################
[...]
> > 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
> 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