compilation error... Am I missing anything?

Discussion in 'C++' started by smilesonisamal@gmail.com, May 17, 2009.

  1. Guest

    class A
    {
    public:
    void SetA(EmployeeCategory a); // EmployeeCategory is a enum
    and is already declared.
    EmployeeCategory GetA() const;

    private :
    EmployeeCategory m_emplCategory; // This is initialized in the
    constructor

    }

    In .cpp file
    --------------
    EmployeeCategory A::GetA() const
    {
    return m_emplCategory;

    }

    Set function works fine. But when I try to return a value for enum I
    get the following error:
    error C2511: ' EmployeeCategory A::GetA() const' : overloaded member
    function not found in 'A'

    I dont understand why this problem comes.

    The following code works:

    A: GetA(EmployeeCategory *eCat)
    {

    *eCat = m_emplCategory;

    }

    Is this a bug in the Visual Studio or I am missing anything?

    Regards
    Soni
     
    , May 17, 2009
    #1
    1. Advertising

  2. * :
    > class A
    > {
    > public:
    > void SetA(EmployeeCategory a); // EmployeeCategory is a enum
    > and is already declared.


    I wonder what made you decide that that declaration could be totally irrelevant?


    > EmployeeCategory GetA() const;
    >
    > private :
    > EmployeeCategory m_emplCategory; // This is initialized in the
    > constructor
    >
    > }
    >
    > In .cpp file
    > --------------
    > EmployeeCategory A::GetA() const
    > {
    > return m_emplCategory;
    >
    > }
    >
    > Set function works fine. But when I try to return a value for enum I
    > get the following error:
    > error C2511: ' EmployeeCategory A::GetA() const' : overloaded member
    > function not found in 'A'
    >
    > I dont understand why this problem comes.


    Because at that point you don't have anything named EmployeeCategory.


    > The following code works:


    No it does not.

    >
    > A: GetA(EmployeeCategory *eCat)


    Here you have a syntax error, hence the code cannot "work" in any sense.


    > {
    >
    > *eCat = m_emplCategory;
    >
    > }
    >
    > Is this a bug in the Visual Studio or I am missing anything?


    The latter.

    A few times. :)

    Summing up: you have decided to (A) *not* provide the relevant information for
    your problem, namely the declaration of EmployeeCategory (but all right, we old
    hands understand from the problem that it's within the class or a base class,
    but you could not know that we'd be familiar with your problem) and you have
    decided to (B) instead provide some *incorrect*, misleading information, which
    is very very counter-productive: it simply doesn't make sense to try to send
    those you ask for help, on a wild goose chase.

    Is that intentional, or?

    If it's not intentional, then please read the FAQ's guidelines on how to post
    (Google for "C++ FAQ Lite").




    Cheers & hth.,

    - Alf

    --
    Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
    No ads, and there is some C++ stuff! :) Just going there is good. Linking
    to it is even better! Thanks in advance!
     
    Alf P. Steinbach, May 17, 2009
    #2
    1. Advertising

  3. Guest

    On May 17, 3:13 pm, "Alf P. Steinbach" <> wrote:
    > * :
    >
    > > class A
    > > {
    > >    public:
    > >        void SetA(EmployeeCategory a);  // EmployeeCategory is a  enum
    > > and is already declared.

    >
    > I wonder what made you decide that that declaration could be totally irrelevant?
    >
    >
    >
    >
    >
    >
    >
    > >        EmployeeCategory GetA() const;

    >
    > > private :
    > >       EmployeeCategory m_emplCategory; // This is initialized in the
    > > constructor

    >
    > > }

    >
    > > In .cpp file
    > > --------------
    > >    EmployeeCategory A::GetA() const
    > > {
    > >      return m_emplCategory;

    >
    > > }

    >
    > > Set function works fine. But when I try to return a value for enum I
    > > get the following error:
    > > error C2511: ' EmployeeCategory A::GetA() const' : overloaded member
    > > function not found in 'A'

    >
    > > I dont understand why this problem comes.

    >
    > Because at that point you don't have anything named EmployeeCategory.
    >
    > > The following code works:

    >
    > No it does not.
    >
    >
    >
    > > A: GetA(EmployeeCategory *eCat)

    >
    > Here you have a syntax error, hence the code cannot "work" in any sense.
    >
    > > {

    >
    > >    *eCat = m_emplCategory;

    >
    > > }

    >
    > > Is this a bug in the Visual Studio or I am missing anything?

    >
    > The latter.
    >
    > A few times. :)
    >
    > Summing up: you have decided to (A) *not* provide the relevant information for
    > your problem, namely the declaration of EmployeeCategory (but all right, we old
    > hands understand from the problem that it's within the class or a base class,
    > but you could not know that we'd be familiar with your problem) and you have
    > decided to (B) instead provide some *incorrect*, misleading information, which
    > is very very counter-productive: it simply doesn't make sense to try to send
    > those you ask for help, on a wild goose chase.
    >
    > Is that intentional, or?
    >
    > If it's not intentional, then please read the FAQ's guidelines on how to post
    > (Google for "C++ FAQ Lite").
    >
    > Cheers & hth.,
    >
    > - Alf
    >
    > --
    > Due to hosting requirements I need visits to <url:http://alfps.izfree.com/>.
    > No ads, and there is some C++ stuff! :) Just going there is good. Linking
    > to it is even better! Thanks in advance!


    sorry my mistake I missed void. But the code works if I pass as a
    pointer. I have tried it. The EmployeeCategory is in a separate header
    file. Not only enum even the following doesnot work. Iam using
    Microsoft Visual C++ 2005 edition.

    //in .h file
    class A {
    public:
    void SetA(long x);
    long GetA() const;

    private:
    long a;

    };

    //In .cpp file
    -------------
    A :: A()
    {
    a = 0;

    }

    A:: SetA(long b)
    {
    a = b;

    }

    long
    A:: GetA() const
    {
    return a; // a is a private member of class A of type long.
    }


    Could you please help me in this regard?

    Regards
    Soni
     
    , May 17, 2009
    #3
  4. * :
    > On May 17, 3:13 pm, "Alf P. Steinbach" <> wrote:
    >>
    >> If it's not intentional, then please read the FAQ's guidelines on how to post
    >> (Google for "C++ FAQ Lite").
    >>
    >> Cheers & hth.,
    >>
    >> - Alf
    >>
    >> --
    >> Due to hosting requirements I need visits to <url:http://alfps.izfree.com/>.
    >> No ads, and there is some C++ stuff! :) Just going there is good. Linking
    >> to it is even better! Thanks in advance!

    >
    > sorry my mistake I missed void.


    you also missed the advice about reading the faq, which in the part where it
    talks about how to post says a few things about quoting


    > But the code works if I pass as a
    > pointer. I have tried it. The EmployeeCategory is in a separate header
    > file.


    all right, same problem different cause then

    just include that header from your .h file


    > Not only enum even the following doesnot work. Iam using
    > Microsoft Visual C++ 2005 edition.
    >
    > //in .h file
    > class A {
    > public:
    > void SetA(long x);
    > long GetA() const;
    >
    > private:
    > long a;
    >
    > };
    >
    > //In .cpp file
    > -------------
    > A :: A()
    > {
    > a = 0;
    >
    > }
    >
    > A:: SetA(long b)


    missing result type


    > {
    > a = b;
    >
    > }
    >
    > long
    > A:: GetA() const
    > {
    > return a; // a is a private member of class A of type long.
    > }



    hth.,

    - alf

    --
    Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
    No ads, and there is some C++ stuff! :) Just going there is good. Linking
    to it is even better! Thanks in advance!
     
    Alf P. Steinbach, May 17, 2009
    #4
    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. Gary Herron
    Replies:
    2
    Views:
    700
    Bruno Desthuilliers
    Jul 4, 2006
  2. C__chp
    Replies:
    4
    Views:
    547
    Puppet_Sock
    Feb 15, 2008
  3. prix prad

    Declaration does not declare anything error

    prix prad, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    4,268
    Andrey Tarasevich
    Oct 2, 2009
  4. prix prad

    Declaration does not declare anything error

    prix prad, Oct 1, 2009, in forum: C Programming
    Replies:
    0
    Views:
    292
    prix prad
    Oct 1, 2009
  5. DanL
    Replies:
    0
    Views:
    130
Loading...

Share This Page