Can someone PLEASE HELP ME!! I am trying to get access to the sorted array in the Mode class, so that I can find the median of the array. The program runs before I created the Statistics class. But I get an error when I try to inherit the Mode class.
It's telling you that the compiler cannot find a Mode constructor with int* and int as parameters. Declare and define a Mode constructor that takes no arguments.
Could you post your code along with [_code_][_/code_] tags please (remove the underscores). Before you do, could you check if you've place a set of parentheses ((...)) after the symbol of the instantiation. If you have, remove them.
The error doesn't reside within the code you posted. Can you post the contents of main( )? This time, can you use this link: http://pastebin.com/ It saves a whole lot of space.
Error:
Mode.cpp:85:5: error: prototype for ‘int Statistics::set_Median()’ does not match any in class ‘Statistics’
Mode.h:73:9: error: candidate is: int Statistics::set_Median() const
You need to place the const qualifier after the function interface (after the parameter list and before the opening brace) of Statistics::set_Median( ). For example:
1 2 3 4 5
// Mode.cpp
int Statistics::set_Median( ) const
{
}
I get another error:
Mode.cpp:85:5: error: redefinition of ‘int Statistics::set_Median() const’
Mode.h:73:9: error: ‘int Statistics::set_Median() const’ previously defined here
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&)
The constructor of the child class calls at the constructor of the parent.
You didn't define any constructor for Statistics, so the compiler created a default one, and it's trying to use the default constructor of Mode (that it does not exists)
Solution: create a proper constructor for StatisticsStatistics::Statistics(): Mode( proper, parameters ){ //...
1 2
//Mode *mode=new Mode(one_Dim,array_size); //don't do this crap
Mode mode(one_Dim, array_size);
protected members of a class are only accessible by the inherited class and by the class that declared them. Therefore, any variable of function (that is not associated with the class) attempting to access protected members are rejected. You need to make Statistics::middle public, or, create a method that returns a non-constant reference to Statistics::middle. However, this will break encapsulation.
Please update your code. Also post the class declaration. some_method( ) const; is telling that it will not modiify the object. You are violating that in set_Median, ¿does it make sense for set_Median to be const?
You never defined a default constructor for Mode. ¿does it make sense to provide one?
I have been working on this program all day and I can't get this program to run. After I fix an error I just keep getting new errors. I am trying to call get_Median but I get an error Please can anyone help?