🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Compiling problem

Started by
2 comments, last by Aesthir 22 years, 10 months ago
I''m currently learning C++ by going through the book "Who''s afraid of C++?" To teach string variables, the author has written his own header file, but when I write a program using his header file, I get the following errors when compiling with Borland''s free commandline compiler: ch3ex5.cpp: Error E2015 string6.h 8: Ambiguity between ''string'' and ''std::string'' Error E2015 ch3ex5.cpp 6: Ambiguity between ''string'' and ''std::string'' in functi on main() Error E2015 ch3ex5.cpp 6: Ambiguity between ''string'' and ''std::string'' in functi on main() *** 3 errors in Compile *** The source code for my program and his header file are the following:
  
ch3ex5.cpp
----------------------------------------
#include <iostream.h>
#include "string6.h"

int main ()
{
  string Name;
  short Age;

  cout << "Please enter your name: ";
  cin >> Name;

  cout << "Please enter your age: ";
  cin >> Age;

  if (Age < 47)
     cout << Name << ", you''re a real youngster!";
  else
     cout << Name << ", you''re really getting on in years.";

  return 0;
}


string6.h
----------------------------------------
#ifndef STRING_H
#define STRING_H
#include <iostream.h>

class string
{
friend ostream& operator << (ostream& s, const string& Str);
friend istream& operator >> (istream& s, string& Str);

public:
    string();
    string(const string& Str);
    string& operator = (const string& Str);
    ~string();

    string(char* p);
    short GetLength();
    bool operator < (const string& Str);
    bool operator == (const string& Str);
    bool operator > (const string& Str);
    bool operator >= (const string& Str);
    bool operator <= (const string& Str);
    bool operator != (const string& Str);

private:
    short m_Length;
    char* m_Data;
};
#endif
  
Anyone know how I can fix it? Thank you for your help.
Advertisement
Try renaming your class from string to something else. I would have thought it works, because you haven''t included the string header, but there is obviously a conflict.

call it myString or something like that, and don''t forget to use that name when declaring Name: string Name; should then become myString Name.

Good luck

- JQ
Infiltration: Losing Ground
"Crap posts are fertilizer. You have to fill the Lounge with crap in order for anything useful to grow." -runemaster
~phil
Should I have to change any of the ''string''s other than the one in the "class string" line? I tried just changing that line and it didn''t work, then I tried changing all the ''string''s and that didn''t work either...
dont rename.
use namespace's. Thats what namespaces are for...

      namespace jwalker  {     class JayString : public string { };   }// to use the JayString// either using namespace jwalker;JayString mystring;//orjwalker::JayString mystring    


{ Stating the obvious never helped any situation !! }

Edited by - jwalker on July 26, 2001 12:02:25 AM

This topic is closed to new replies.

Advertisement