D
Daz
Hi Everyone. Please could someone explain how I can go about adding
separate member functions to stock.add? For example,
stock.add.count(int) and stock.add.value(int)?
This way I can hopefully add to both 'cnt' and 'val'. This class
doesn't serve much of a purpose other than to help me learn about
classes (as this is my first).
Would I need to create another class, and add it as a friend to my
exisiting class? If so, what about the classes global variables?
Any help would be greatly appreciated as always. )
-----------------------------------CODE
START-----------------------------------------
#include <iostream>
using namespace std;
using std::string;
using std::cout;
using std::endl;
class stock
{
signed long int val;
long int cnt;
public:
stock () { val = 0; count = 0; };
stock (int a) { val = a; count = 0; }
void add (int a) { val = val + a; }
void subtract (int a) { val = val - a; }
signed int value() { return val; }
};
int main ()
{
stock pawn;
pawn.add(5);
pawn.add(6);
cout << pawn.value() << endl;
return 0;
}
-----------------------------------CODE
END-----------------------------------------
separate member functions to stock.add? For example,
stock.add.count(int) and stock.add.value(int)?
This way I can hopefully add to both 'cnt' and 'val'. This class
doesn't serve much of a purpose other than to help me learn about
classes (as this is my first).
Would I need to create another class, and add it as a friend to my
exisiting class? If so, what about the classes global variables?
Any help would be greatly appreciated as always. )
-----------------------------------CODE
START-----------------------------------------
#include <iostream>
using namespace std;
using std::string;
using std::cout;
using std::endl;
class stock
{
signed long int val;
long int cnt;
public:
stock () { val = 0; count = 0; };
stock (int a) { val = a; count = 0; }
void add (int a) { val = val + a; }
void subtract (int a) { val = val - a; }
signed int value() { return val; }
};
int main ()
{
stock pawn;
pawn.add(5);
pawn.add(6);
cout << pawn.value() << endl;
return 0;
}
-----------------------------------CODE
END-----------------------------------------