error: request for member of non-class type

Discussion in 'C++' started by Andre, Nov 18, 2007.

  1. Andre

    Andre Guest

    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;
    }
    #####################################
     
    Andre, Nov 18, 2007
    #1
    1. Advertising

  2. Andre

    Kai-Uwe Bux Guest

    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
     
    Kai-Uwe Bux, Nov 18, 2007
    #2
    1. Advertising

  3. Andre

    Jim Langston Guest

    "Andre" <> wrote in message
    news:...
    > 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;
    > }
    > #####################################
     
    Jim Langston, Nov 18, 2007
    #3
  4. Andre

    James Kanze Guest

    On Nov 18, 3:22 am, Kai-Uwe Bux <> 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:
    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
     
    James Kanze, Nov 18, 2007
    #4
  5. Andre

    Kai-Uwe Bux Guest

    James Kanze wrote:

    > On Nov 18, 3:22 am, Kai-Uwe Bux <> 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
     
    Kai-Uwe Bux, Nov 18, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,792
    Thomas Weidenfeller
    Oct 12, 2005
  2. ghager
    Replies:
    6
    Views:
    623
    ghager
    Jan 19, 2006
  3. ztycho
    Replies:
    1
    Views:
    1,063
    joseph cook
    Aug 11, 2008
  4. AJ
    Replies:
    6
    Views:
    1,393
    Joe Greer
    Dec 4, 2009
  5. zl2k
    Replies:
    2
    Views:
    1,434
    Saeed Amrollahi
    Sep 13, 2010
Loading...

Share This Page