Function call with parameters that may be unsafe error

Hey, I was trying to implement this Tnode class that has to store array of chars on free store to represent word and a simple count variable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <string>
#include <algorithm>
#include <iostream>

struct Tnode {

	char* word;
	int count;
	Tnode* left;
	Tnode* right;

	Tnode(const std::string&, int);
	~Tnode() { delete[] word; }
};

Tnode::Tnode(const std::string& s = {}, int i = {}) :  count{ i }, left{ nullptr }, right{ nullptr } {
	word = new char[s.size()+1];

	std::copy(s.begin(), s.end(), word);       //<------------- Something wrong here ???
	word[s.size()] = '\0';
}


int main() {

	Tnode node{"bear", 50};

	return 0;
}


For some reason compiler doesn't like this line
std::copy(s.begin(), s.end(), word);
and here is the error message
Severity Code Description Project File Line
Error C4996 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' exercise_8 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility 2230

What is so wrong about it?
Last edited on
Microsoft don't like a number of standard functions so they throw this warning when you use some functions they don't like. They want you to use different functions.
Last edited on
Ok update : when I compile it in cpp.sh website it works just fine but my Visual Studio 2015 doesnt like it for some reason. So code must be fine.
Last edited on
Ok tnx for answer man appreciate it :)
Topic archived. No new replies allowed.