troubleshooting Question

help with overwriting std::string operator=

Avatar of graber
graberFlag for United States of America asked on
C++.NET ProgrammingVisual Basic.NET
7 Comments1 Solution2005 ViewsLast Modified:
is it possible to call base class functions like we do with the constructors? compilers has a conipsion on the first operator member... no problem with the second... any reasons? also tell me what level is this question... Thanks.
#include <string>
using namespace std;
class CWord: public string
{
   public:
      CWord();
      CWord(const string & str);
      CWord(const string & str, size_t pos, size_t n = npos);
      CWord(const char * s, size_t n);
      CWord(const char * s);
      CWord(size_t n, char c);
      CWord & operator=(const CWord & word);
      CWord & operator=(const string & str);
      CWord & operator=(const char * psz);
   protected:
   private:
      char m_cDelimiter;
};
 
doesn't work
CWord & CWord::operator=(const CWord & word)
              :string(word.c_str())
{
   assign(word.c_str());
   return * this;
}
 
works
CWord & CWord::operator=(const CWord & word)
{
   assign(word.c_str());
   return * this;
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros