I added the extra Mode(); to fix one of my previous errors:
In file included from main.cpp:37:0:
Mode.h:61:23: error: no matching function for call to ‘Mode::Mode()’
Mode.h:23:6: note: candidates are: Mode::Mode(int*, int)
Mode.h:10:12: note: Mode::Mode(const Mode&)
Why did you post another thread about this same topic...?
And it's as I said, you need to define the default constructor. If you don't know how to define a function, you should go look it up in your textbook or a tutorial. Though if your professor is giving this much code, I'd expect you to know at least the basics of C++.
So the default constructor allows me access to the Mode class? If so, then what would I need to define in mode(); to allow me access to the Mode class?
You don't need to define anything in it if you don't want to. It's simply that Statistics automatically calls the default constructor of Mode to construct the members it inherits. If you want to avoid that, you could use an intializer list.
I think you should get back to the basics. You shouldn't be playing around with classes if you do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int Statistics::set_Median(){ /*why does this "setter" not take any arguments, but return a value?
If you want this function to return the median, call it "getMedian" or something like that*/
middle=bSize/2;
if(middle%2==0)//Calculate if size of array is even or odd
{
median=middle;//((b[middle]) + (b[middle-1]))/2;
}
else
{
median=middle;//b[middle];
}
int set_Median(median); //this is a function declaration
}
@hanst99:
If I were to guess, I would say, he is setting the Median for that object, from other given data.
Like I used a function, SetStr(); in the Class for handling Complex Numbers, which would make it in the form: <Real_Part> + i<Imaginary_Part>
The function took no arguments, butwasn't even called directly, but included in some other class methods, like those that would set the Real r Imaginary value...
¿which array? (I guess that int *b; in Mode. posting the headers could help)
¿where do you put anything in that array? ¿where do you set the value of bSize?
hanst99 wrote:
int set_Median(median); //this is a function declaration
Nope, I made the same mistake. That is creating a variable (an integer) and set it to the value of median. It is using the same name as the function, thought (scope resolution).
So @OP, this ain't Pascal. To return a value from a function you use return value;
Main.cpp fills an array with random numbers which then I pass to nMode() to get the array sorted out and store the sorted array to *b in the Mode class.
I am trying inherit the sorted array b and the size of the array bSize into the Statistics class, so that I can calculate the median of the sorted array.
After analyzing this code I have one question, Why do you use two different variable accesses from a constructor, which isn't a copy constructor, than all other functions?
You are coping an array into a new object, not coping the object. The code would look very different and would use the "This" pointer to manage a object to object copy, which is not what you are trying to do.
Simply put the constructor should look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Mode::Mode(int *a,int s)
{
//Copy the array
bSize=s;
b = newint[s];
for(int i=0;i<s;++i)
{
b[i]=a[i];
}
//Sort then find the mode
mark_Sort(b, s);
nMode();
}
My opinion you are trying to access two different objects at the same time through your code. In other words the virtual table is screwed up for the objects. You would end up calling two different functions from any inheritances. I didn't understand the need for the complexity. You are not dealing with a virtual constructor or a purely virtual object.