Hello,
I have an assignment I have been struggling with,specifically with regards to calling a function from within a member function. Instead of using the actual assignment, I have thrown together an example to in hopes that someone could point me in the right direction. my example is comprised of two header files and two source files.
Code:
// somenum.h
#ifndef SOMENUM_H
#define SOMENUM_H
int aNumber(int num, int num2);
#endif
//second.h
#ifndef SECOND_H
#define SECOND_H
struct Value {
int zero;
int one;
Value(int num1, int num2);
void addNum (int value1, int value2);
}
//number.cpp
#include "second.h"
#include "somenum.h"
using namespace std;
Value value ( int a, int b)
{
zero = a;
one = b;
};
void Value::addNum(int someVal1, int someVal2)
{
//call aNumber here, pass params
}
//somenum.cpp
#include "somenum.h"
using namespace std;
int aNumber(int num, int num2)
{
int num3 = num + num2;
return num3;
}
Hopefully my example makes sense, I didn't include a main() as it doesnt come into play at this point. Basically I want to call aNumber inside addNum, but I have not been able to figure out how to accomplish this. I have tried the following:
Code:
void Value::addNum(int someVal1, int someVal2)
{
aNumber(someVal1, someVal2);
}
void Value::addNum(int someVal1, int someVal2)
{
value.aNumber(someVal1, someVal2);
}
void Value::addNum(int someVal1, int someVal2)
{
Value value;
value.aNumber(someVal1, someVal2);
}
If someone could help me out I would greatly appreciate it.