Here is my code:

std::string resolve_email(int *email){ char* c = new char[email.length() + 1];//error: request for member 'length' in 'email', which is of non-class type 'int*' for(int i = 0; i < email.length(); i++){ c[i] = email[i];//error: request for member 'length' in 'email', which is of non-class type 'int*' } return std::string(c); } 

I get when I compile the error (added to the code as a comment). What is wrong here?

  • Wrong language. English is working language at stackoverflow.com, but you are at ru.stackoverflow.com. - VladD
  • I understood it, thanks - Nurislam Fazulzyanov
  • Judging by the code, you want to get a copy of the email in the type std::string . Where did you get the email argument in the form of an array of integers? - avp

1 answer 1

From which language did you move to C ++?

The pointer knows nothing about how many elements it indicates, so the length of the array must be passed along with the pointer.

But what exactly do you want to do? I generally don’t understand the purpose of your body movements: create an array of char , chop off int to char and stuff it into a string for some reason, also causing a memory leak.

State your goal, because you can only guess what you want ... And do it terribly wrong.

  • I haven't written in c ++ for a long time (more than a year, mainly python and JS). - Nurislam Fazulzyanov
  • how to make an array of characters take the size of an array int - Nurislam Fazulzyanov
  • Use not an array, but a vector , or pass a second parameter to the function — the length of the array. But in general, you obviously do something wrong! Let's not ask which hand to hold the microscope for hammering nails - tell us about the nails themselves, in order to choose what to hammer them in. - Harry