Overloades member function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krish

    #1

    Overloades member function

    Hi There,

    I am having problem when I compile a code which I create to test a
    source file. The errors are :
    error C2144: syntax error : 'void' should be preceded by ';'
    error C2511: 'void CNewServiceApp: :function(SER,D WORD,LPVOID)' :
    overloaded member function not found in 'CNewServiceApp '

    Can someone help me to solve this?
    Thanks,
    Krish

    HeaderFile
    class CNewServiceApp : public CWinApp
    {
    public:
    CNewServiceApp( );

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(C NewServiceApp)
    public:
    virtual BOOL InitInstance();
    //}}AFX_VIRTUAL

    // Implementation
    //func(int);
    //func(this);

    static DWORD CALLBACK function(CServi ce*, DWORD, LPVOID);
    DWORD function(CServi ce*, DWORD);

    LPVOID arg;

    //{{AFX_MSG(CNewS erviceApp)
    // NOTE - the ClassWizard will add and remove member functions here.
    // DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE _MAP()
    };

    CPP file:

    BOOL CNewServiceApp: :InitInstance()
    {
    AfxEnableContro lContainer();

    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need.

    arg = this;

    MyService = new CService("NewSe rvice",function , this );


    return FALSE;

    }



    typedef CService SER
    void CNewServiceApp: :function(SER A, DWORD na, LPVOID arg)
    {
    CNewServiceApp *pCNewServiceAp p;

    if (arg == NULL)
    {
    return FALSE;
    }

    pCNewServiceApp = (CNewServiceApp *)arg;

    return pCNewServiceApp ->function(A, arg);

    }
  • David Hilsee

    #2
    Re: Overloades member function

    "Krish" <krish_jasmin@y ahoo.ca> wrote in message
    news:b8dab48e.0 409291838.79881 242@posting.goo gle.com...[color=blue]
    > Hi There,
    >
    > I am having problem when I compile a code which I create to test a
    > source file. The errors are :
    > error C2144: syntax error : 'void' should be preceded by ';'
    > error C2511: 'void CNewServiceApp: :function(SER,D WORD,LPVOID)' :
    > overloaded member function not found in 'CNewServiceApp '
    >
    > Can someone help me to solve this?
    > Thanks,
    > Krish
    >
    > HeaderFile
    > class CNewServiceApp : public CWinApp
    > {
    > public:
    > CNewServiceApp( );
    >
    > // Overrides
    > // ClassWizard generated virtual function overrides
    > //{{AFX_VIRTUAL(C NewServiceApp)
    > public:
    > virtual BOOL InitInstance();
    > //}}AFX_VIRTUAL
    >
    > // Implementation
    > //func(int);
    > //func(this);
    >
    > static DWORD CALLBACK function(CServi ce*, DWORD, LPVOID);
    > DWORD function(CServi ce*, DWORD);
    >
    > LPVOID arg;
    >
    > //{{AFX_MSG(CNewS erviceApp)
    > // NOTE - the ClassWizard will add and remove member functions here.
    > // DO NOT EDIT what you see in these blocks of generated code !
    > //}}AFX_MSG
    > DECLARE_MESSAGE _MAP()
    > };
    >
    > CPP file:
    >
    > BOOL CNewServiceApp: :InitInstance()
    > {
    > AfxEnableContro lContainer();
    >
    > // Standard initialization
    > // If you are not using these features and wish to reduce the size
    > // of your final executable, you should remove from the following
    > // the specific initialization routines you do not need.
    >
    > arg = this;
    >
    > MyService = new CService("NewSe rvice",function , this );
    >
    >
    > return FALSE;
    >
    > }
    >
    >
    >
    > typedef CService SER
    > void CNewServiceApp: :function(SER A, DWORD na, LPVOID arg)
    > {
    > CNewServiceApp *pCNewServiceAp p;
    >
    > if (arg == NULL)
    > {
    > return FALSE;
    > }
    >
    > pCNewServiceApp = (CNewServiceApp *)arg;
    >
    > return pCNewServiceApp ->function(A, arg);
    >
    > }[/color]

    I'm going to try to ignore all of the unexplained stuff that resembles MFC
    and answer your questions as they pertain to the C++ language.

    First of all, the line reading

    typedef CService SER

    needs a semicolon

    typedef CService SER;

    And, AFAICT, you were trying to declare and define a member function of
    CNewServiceApp (CNewServiceApp ::function) that takes a CService*, so
    wouldn't you use

    void CNewServiceApp: :function(SER * A, DWORD na, LPVOID arg)

    in the definition? After all, SER is a typedef for CService, not a pointer
    to a CService. If I were you, I would move the typedef so I could use it in
    both the declaration and the definition, but that's entirely up to you.

    --
    David Hilsee


    Comment

    • John Harrison

      #3
      Re: Overloades member function


      "David Hilsee" <davidhilseenew s@yahoo.com> wrote in message
      news:96KdnTzz_N PO6MbcRVn-sA@comcast.com. ..[color=blue]
      > "Krish" <krish_jasmin@y ahoo.ca> wrote in message
      > news:b8dab48e.0 409291838.79881 242@posting.goo gle.com...[color=green]
      >> Hi There,[color=darkred]
      >>>[/color][/color]
      > First of all, the line reading
      >
      > typedef CService SER
      >
      > needs a semicolon
      >
      > typedef CService SER;
      >
      > And, AFAICT, you were trying to declare and define a member function of
      > CNewServiceApp (CNewServiceApp ::function) that takes a CService*, so
      > wouldn't you use
      >
      > void CNewServiceApp: :function(SER * A, DWORD na, LPVOID arg)
      >
      > in the definition? After all, SER is a typedef for CService, not a
      > pointer
      > to a CService. If I were you, I would move the typedef so I could use it
      > in
      > both the declaration and the definition, but that's entirely up to you.
      >[/color]

      If I were the OP I'd just remove the typedef entirely. After all what is the
      point of

      typedef CService SER;

      Why not just use CService throughout and avoid confusing everybody
      (including yourself).

      john


      Comment

      • Krish

        #4
        Re: Overloades member function

        Thanks for you replies.

        I have a question, if I have a global function that pointed to class
        or object, then how do I pass arguments to that function.
        I have CService *MyService; in my cpp
        and in my header, i have
        static DWORD CALLBACK function(CServi ce*, DWORD, LPVOID);
        DWORD func(CService*, DWORD);

        then how do i pass argument for that pointer.
        CNewServiceApp: :function(-------, DWORD R, LPVOID arg);
        what should I put in ----- above.

        Krish


        "John Harrison" <john_andronicu s@hotmail.com> wrote in message news:<2s1miqF1g fiefU1@uni-berlin.de>...[color=blue]
        > "David Hilsee" <davidhilseenew s@yahoo.com> wrote in message
        > news:96KdnTzz_N PO6MbcRVn-sA@comcast.com. ..[color=green]
        > > "Krish" <krish_jasmin@y ahoo.ca> wrote in message
        > > news:b8dab48e.0 409291838.79881 242@posting.goo gle.com...[color=darkred]
        > >> Hi There,
        > >>>[/color]
        > > First of all, the line reading
        > >
        > > typedef CService SER
        > >
        > > needs a semicolon
        > >
        > > typedef CService SER;
        > >
        > > And, AFAICT, you were trying to declare and define a member function of
        > > CNewServiceApp (CNewServiceApp ::function) that takes a CService*, so
        > > wouldn't you use
        > >
        > > void CNewServiceApp: :function(SER * A, DWORD na, LPVOID arg)
        > >
        > > in the definition? After all, SER is a typedef for CService, not a
        > > pointer
        > > to a CService. If I were you, I would move the typedef so I could use it
        > > in
        > > both the declaration and the definition, but that's entirely up to you.
        > >[/color]
        >
        > If I were the OP I'd just remove the typedef entirely. After all what is the
        > point of
        >
        > typedef CService SER;
        >
        > Why not just use CService throughout and avoid confusing everybody
        > (including yourself).
        >
        > john[/color]

        Comment

        Working...