Here's me error:"invalid conversion from 'char*' to 'char'.
This is much different than what I found on google because I'm using actual pointers not return values n' stuff.
Well heres a watered down version of the code:

char* LOCK = new char[501];
char ret[501] = "this is fine in program";

The last line is getting the error.
Two more things:
It is very important it is a c-style string (array if chars)
It is very important that it uses the heap.

The memory allocated to the heap is deleted after a while.

Recommended Answers

All 2 Replies

you just can't arbitrarily assign a const char cstring to a buffer. it physically has to be copied element by element. the <cstring> library has everything you need to make cstring assignments:

#include <cstring>

char* lock = new char[501];

char ret[501] =  "this is a fine program";

strcpy(lock, ret);

the low-level power of c is cool, but when you take on the responsibility for allocating your own blocks of memory, you need some tools to help with handling character arrays (in this case, the tools are in the <cstring> library).

in contrast, a more object oriented approach would be to use the <string> class, which does offer an overloaded = assignment operator that would allow ye' to assign a string literal to a string class object.

The reason that it had to be a c-style string is that I'm handling filenames and if I try to use string with this I get an error. The reason that I have to use the heap is so that I could put some data in it and keep it because this is going in a dll and several other functions would use this same data and I'm not sure if switching files zooms the variables scope too far so this will Prevent a global variable from being unallocated. I know of no way to move data manually to the heap (eg not with a pointer).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.