title: C++ - Assigning null to a std::string
body: <p>I am learning C++ on my own. I have the following code but it gives error. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  
  int setvalue(const char * value)
  {
      string mValue;
      if(value!=0)
      {
         mValue=value;
      }
      else
      {
         mValue=0;
      }
  }
  
  int main ()
  {
   const char* value = 0;
   setvalue(value);
  
   cin.get();
   return 0;
  }
  </code></pre>
  
  <p>So want to create a function which accepts char pointers and I want to pass a pointer to it. The function assigns the pointer to its member variable. I'm passing a null pointer intentionally. Following is the error I'm getting: </p>
  
  <pre><code> D:\CPP\TestCP.cpp In function `int setvalue(const char*)': 
  
   note C:\Dev-Cpp\include\c++\3.4.2\bits\basic_string.h:422 candidates are: std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp; std::basic_string&lt;_CharT, _Traits, _Alloc&gt;::operator=(const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, _Alloc = std::allocator&lt;char&gt;] 
  
   note C:\Dev-Cpp\include\c++\3.4.2\bits\basic_string.h:422                 std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp; std::basic_string&lt;_CharT, _Traits, _Alloc&gt;::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, _Alloc = std::allocator&lt;char&gt;] 
  
   note C:\Dev-Cpp\include\c++\3.4.2\bits\basic_string.h:422                 std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp; std::basic_string&lt;_CharT, _Traits, _Alloc&gt;::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, _Alloc = std::allocator&lt;char&gt;] 
  </code></pre>
  
  <p>it's basically complaining about line:   mValue=0;</p>
  
  <p>Why is it complaining about this line? I can't assign a null to a String?</p>