You are here:

C++/hello, about passing functions again..(Part II)


Oh, I'm sorry I forgot to add this on the previous question.

And if I do this:
int system(string sub_Name, string file_Name, string String_System[256][2], int Count_System){

I get another compile error message as follows:
Error E2015 test.cpp 52: Ambiguity between 'std::basic_string<char,std::char_traits<char>,std::allocator<char> >::operator =(const char *)' and 'std::basic_string<char,std::char_traits<char>,std::allocator<char> >::operator =(char)' in function shenu(std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > (*)[2],int)

A very sophisticated error.
I guess this has something to do with the name spacing?

and I typed in
using namespace std;
in the global area.
Thanks again.

Oddly, although you get a load of very long names in the error this is due to expanding the names of all the class templates used by the standard C++ library and in fact can be a real problem in seeing what is actually the problem.

The problem here is:


This is because 0 could either be the integer 0 as a char (which is often in code given as a character literal '\0') or it could be a null pointer value as 0 is always convertible to a null pointer.

This in itself is not a problem except that to be helpful a std::string (which is a specific type of std::basic_string<>) can have both characters assigned to it as in:

       std::string a_string;
       a_string = 'a';

Or it can have a C-style string (such as a C/C++ literal string) assigned to it:

       std::string c_string;
       c_string = "C style literal string";

In C a string was by convention an array of characters terminated by a '\0' character. In C and C++ the built in array type is represented by an area of contiguous memory and the name of the array is a pointer to that area. Hence there is a strong link between built in array types and pointers and in most cases where you use an array you can use a pointer, for example:

       char char_array [10];
       char * pointer_to_char = char_array;
       pointer_to_char[0] = 'a';
       pointer_to_char[1] = 'b';
       pointer_to_char[2] = '\0'; // now we have a C-style string "ab"

       char chr = *(char_array + 1); // chr == 'b'

In fact using a[n] is the same as using *(a + n).

As this is an aside and covered in any good C or C++ text I shall not dwell further on this issue.

The main point is that usually we pass C-style strings as char * or char const * if they are not to be modified.

So the std::string class has overloaded assignment operators ( operator=() ) for both char and char const *. These allow you to use std::string objects as I showed above. Unfortunately in the case of 0 it can be taken to mean either a char or a char const *. As there is no way to pick one of the two candidate assignment operators over the other – that is assuming 0 to be char is equally as good as assuming it is a char const * - the compiler fails to resolve the set of functions you are calling to only one and emits and error.

Note that you are calling a function even though it is implicit – when you use = the operation either resolves to a built in assignment operation or to an overloaded operator= function specifically written for the types involved. There may be more than one such possible function for the types involved and there are a set of rules for ranking the suitability of these possible candidate functions. However if after applying these rules the compiler still has more than one function to choose from the program is in error.

In this case I presume you wish to create an empty string. Things to about std::string are that by default they are created empty and that you can use the erase or clear member functions to reset the contents to an empty string. So maybe you meant to say:


If you are using the standard C++ library a lot then I suggest you get yourself a good reference such as “The C++ Standard Library A Tutorial and Reference” by Nicolai M. Josuttis. I use my copy regularly – it is always with me even when working at client sites.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2016 All rights reserved.