Link to home
Start Free TrialLog in
Avatar of jsab500
jsab500

asked on

Really really simple question about member functions in classes

I mean really really simple.

All i want to do is make a class (in Visual C++ 2008) A  that has two int members b and c, and a function d  that adds them together. What i wrote is this:

-------------------A.h--------------------------
#ifndef A_H
#define A_H
#pragma once

class A
{
public:
      int b;
      int c;
      int d();
};
#endif
------------------------------------------------

-----------------A.cpp-------------------------
#include "A.h"

int d()
{
      int r = b + c;
      return r;
}
---------------------------------------------------

With this it tells me that in A.h, b and c are undeclared identifiers.
With A::b and A::c in A.h instead of just b and c it says "error C2597: illegal reference to non-static member 'A::b'" and i don't want them to be static members.

Anyone tell me what the correct method of doing this is?

Thanks a lot for your help.
James

ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That translates to:

int A::d()
{

}



Good Luck,
Kent