Hello!
This is my first post here. After having spent countless hours on forums with a gazillion tabs open trying to find a solution to my problem, I feel that I now have no other choice but to ask for your help.
What really bugs me is that this is supposed to be really easy to complete, but I just can't wrap my head around it! This has taken me far too long.
The code consists of one .h file and three cpp files.
This is the .h file:
Code:Code:#include <iostream> #include <ctime> #include <cstdlib> usingnamespacestd; class heltal { private: int tal; public: heltal(); heltal(int nmr); void setValue(int value, int nmr); int getValue() const; heltal operator< (heltal &heltal); heltal operator> (heltal &heltal); }; class Array { private: heltal *ptrHeltal; int size; public: Array(); Array(int arraysize); ~Array(); int generate_numbers(int arraysize, int high, int low) { int i; srand((unsigned)time(0)); cout << "\n\nThe generated numbers are:\n"; for (i = 0; i <= arraysize; i++) { ptrHeltal[i] = (rand() % high + low); cout << "\n" << ptrHeltal[i]; } return 0; } };
This is a cpp file called "array.cpp":
Code:#include <iostream> #include <ctime> #include <cstdlib> #include "heltal.h" usingnamespacestd; Array::Array() { size=50; ptrHeltal = newheltal[size]; } Array::Array(int arraystorlek) { size = arraystorlek; ptrHeltal = newheltal[size]; } Array::~Array() { delete []ptrHeltal; }
This is another cpp file called "heltal.cpp":
Code:#include <iostream> #include "heltal.h" usingnamespacestd; heltal::heltal() { tal = 0; } heltal::heltal(int nmr) { nmr = tal; } void heltal::setValue(int value, int nmr) { nmr = value; } int heltal::getValue() const { return tal; } heltaloperator< (heltal tal, heltal value) { tal = value; return tal; } heltaloperator> (heltal tal, heltal value) { value = tal; return value; }
And lastly, this is the "main.cpp":
Code:#include <iostream> #include "heltal.h" usingnamespacestd; int main() { int arraysize; int high; int low; cout << "How large should the array be?" << endl; cin >> arraysize; cout << "What should the lowest number be?" << endl; cin >> low; cout << "What should the highest number be?" << endl; cin >> high; Array run(arraysize); run.generate_numbers(arraysize, high, low); return 0; }Code:
And now to my issue. In the "heltal.h" function generate_numbers, I can't seem to print the array "heltal[i]". I get this error saying:
"Invalid operands to binary expression ('basic_ostream<char, std::__1::char_traits<char>>' and 'heltal')
What in the world is the meaning of this? Is the problem somewhere else in my code or should I print the array in a different way?
I am absolutely hopelessly clueless and would be immensely happy if anyone could just give me a hint as to why I'm failing!
For those of you who have read this long thread, thank you!



LinkBack URL
About LinkBacks




stream& operator << (std:
I used to be an adventurer like you... then I took an arrow to the knee.