0
Why my program doesn't work
1. In function "&ostream operator<<" I need to write attributes of class because program doesn't show me them . For example in for loop, when I type "obj." program only give me access to public functions I declared function as friend. 2. How I can write "&ostream operator<<" function outside of class "Some"? 3. Is anything else wrong with my program. https://code.sololearn.com/c2a105A21A15/?ref=app
4 Réponses
+ 5
Your code is looking good
There is Little bit problems
but 👍
0
u need to fix the errors in ur code first
that expandArray method doesnt work well, _array is still nullptr, yet u try to access it (_array[i])
inside that add method, u cant do _array variable like an array(_array[currentSize] = obj),cause it is a pointer..
for the ostream operator , the problem is u just forget to add <T1,T2>(const Some<T1,T2>& some) and also that empty _array u want to print
0
The critical issue is the last lines in Add().
delete[] _array1, _array2;
Only one opponent can be apply to delete[]. _array2 is not deleted in this line.
You don't check if both arrays are nullptr in Add(). In this case the alternative is check currentSize to achieve the same thing.
temp1 = _array1;
temp2 = _array2;
Shouldn't it be reversed?
That's basically the critical problem. The minor problem is the comparison, You declare i as size_t in for loop and comparing it to an integer currentSize, generate a compiler warning because this imply an implicit conversion and might not result what you want.
An example of this:
int h = -4;
unsigned int x = 9;
cout << (x > h);
the output is 0 because h is converted to unsigned int, 2^32-4.
1. What do you mean?
2. If the use is to separate the file: check https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
if is for other uses. Why?