Hey! I was hoping to get some help with classes and structs. I've already read the forums relating to my problem, and they've helped so far, but now I'm stuck.
Below, I have two classes and a struct within a class. Right now it compiles as is, but when I make the array declaration visible in the '
add' function, I get an error pointing to line 38 saying:
there is no matching function for call to 'Finish::Finish()'
Within the struct, i can change the type '
Finish' to type '
int', which allows me to make the array declaration visible, but when I go to assign
'good[0].high = k.getB'
an error pops up saying:
cannot convert 'Finish::getB' from type 'int (Finish::)()' to type 'int'|
which is understandable, but I don't know how to fix it. There's also a vector declaration, but I'd much rather use a struct. Anyone know what to do or where else to look?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Finish{
int a, b;
public:
int getA(){return a;}
int getB(){return b;}
Finish (int h, int j);
int other(){
int f = b-a;
return f;
}
};
class Start{
int num, jar;
std::vector<Finish> soo;
///struct instead?
struct Struct{ ///Trying to make this struct
Finish low; ///work with 'Finish' type variables
Finish high; ///
};
public:
Start (int,int);
int answer() {
int d = num+jar;
return d;
}
void test(Finish m){
cout<<m.getA()<<endl;
cout<<endl<<m.getA()+m.getB()<<endl<<endl;
cout<<jar-num<<endl<<endl;
///add elements to vector 'soo'?
///or
///add elements to Struct?
}
void add(Struct, Finish k){ ///pass through class 'Finish' and struct 'Struct'
///Struct * good = new Struct[1000]; <---trying to set up an array
///good[0].high = k.getB; <---trying to take in values from class 'Finish'
}
};
Start::Start (int c, int d){
num = c;
jar = d;
}
Finish::Finish (int h, int j)
: a(h), b(j)
{}
|
P.S. This problem relates to a project I'm working on now, this code is just used to play around and find out how things work (in this case, classes and structs). The architecture is very similar, so there's little I can do to move things around, if that makes sense.