I've recently been relearning C++ and creating an application in hand with what I'm learning and even branching out to figure out concepts that aren't necessarily normal. As dangerous as I see this being, I am still diving head first.
That being said the application I'm currently working on requires storing some info in a local database which I will then be merging with a server database at some point in the future to allow for more in-depth queries and a better UI. While diving into learning SQLite3 integration with C++ I've found that a lot of the integration is specifically "C/C++" with, what appears to be, a stronger foot in C than C++. With this realization I've come across one very specific tutorial that leaned on C++ over C minus the specific issue I'm encountering.
https://www.dreamincode.net/forums/topic/122300-sqlite-in-c/
I actually rather like the concise nature of the Database.cpp that the author of the tutorial created and I want to utilize it. The problem is C++ likes to throw the conversion warnings that apparently work due to the use of C, but are deprecated in C++.
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Technically this can be bypassed by casting the string to (char*). While I understand this it seems I may be missing some information as well. Could this be bypassed by changing the parameters of the Database function to "string*" then converting it to "char*" in the function or should I not care about the implicit conversion and just ignore it. I really don't want to cross C and C++ in my application so I would prefer to paid heed to the warning. Figured I'd ask for advice to at least get some clarification though.
If it seems obvious from my inquiry that I am lacking in some very specific section of my C++ knowledge please feel free to let me know. I am nothing if not diligent when it comes to making sure I can fill all the gaps in my knowledge on any given topic.
std::string::c_str()method in your favorite C++ Reference.void foo(char* name)which is called likefoo("Name");but"Name"is aconst char*notchar*. So, just addconstin the function declaration (e.g.,void foo(const char* name)).constpointers in C either. My experiences with sqlite have found it to beconstcorrect, so you should be able to follow @JamesAdkison 's advice and merely make the tutorial codeconst-correct and happy in modern C++. In general, don't cast unless you can't fix whatever is making you cast.