I can't use string because of task conditions, so it must be char*. There is problem with dynamic array in constructor. Error "'=': cannot convert 'char*' to 'char'"
#include <iostream>
class Line {
public:
const int Size = 10;
char* DynamicLines = new char[Size];
int counter = 0;
Line(char* otherline) {
if (counter < Size) {
DynamicLines[counter] = otherline;
counter++;
}
std::cout << "constructor called\n";
}
~Line() {
delete[] DynamicLines;
std::cout << "destructor called\n";
}
void Print();
};
void Line::Print() {
this->counter = 0;
std::cout << DynamicLines[counter] << "\n" << "length = ";
counter++;
}
void main()
{
char* temp = new char;
std::cin >> temp;
Line Fline(temp);
Fline.Print();
delete temp;
system("pause");
}
char *DynamicLinesis pointer to an array ofchar. Therefore each entry in the array, is achar, not achar*(pointer).Your constructor accepts a pointer to
charwhich needs to be dereferenced, in order to access thecharin the memory and store it in the array.So: