c++: invalid conversion from 'int' to 'const char*'

Boris Samorodov bsam at ipt.ru
Sat Sep 12 09:38:19 UTC 2009

Hello List,

I'm porting a c++ application to FreeBSD. I've got an error:
~/work/src/FileChannel.cpp: In member function 'QString FileChannel::errorString()':
~/work/src/FileChannel.cpp:251: error: invalid conversion from 'int' to 'const char*'
~/work/src/FileChannel.cpp:251: error:   initializing argument 2 of 'char* strcpy(char*, const char*)'
*** Error code 1

A simle patch makes the application to be compiled without errors:
--- src/FileChannel.cpp.orig	2009-09-12 13:08:28.000000000 +0400
+++ src/FileChannel.cpp	2009-09-12 13:08:41.000000000 +0400
@@ -248,7 +248,7 @@
 QString FileChannel::errorString()
-    strcpy(lastErrorString, strerror_r(errno, lastErrorString, 0));
+    strcpy(lastErrorString, "XXX: Fix me: errno should be here");
     return QString(trUtf8(lastErrorString));

If I understand correctly, an integer value which is returned by
strerror_r() should be converted to const char*.

I have _very_ basic knowledge about c++. Hence my question.
Can someone provide a patch (a proof of concept)? Thanks!

WBR, Boris Samorodov (bsam)
Research Engineer, http://www.ipt.ru Telephone & Internet SP
FreeBSD Committer, http://www.FreeBSD.org The Power To Serve

More information about the freebsd-questions mailing list