| | |
STL developers lazy or did I miss something?
![]() |
string a = "A";
string b = "B";
string c = a + b;
string d = "D" + a;
string e = a + "D";
string f = "F" + "F";
Why is the last line not something the string class can handle if it can handle cases a, d, and e?
line 73: Error: The operation "const char* + const char*" is illegal.
(Also, is this something that I could add myself? By developing another + operator for string?)
string b = "B";
string c = a + b;
string d = "D" + a;
string e = a + "D";
string f = "F" + "F";
Why is the last line not something the string class can handle if it can handle cases a, d, and e?
line 73: Error: The operation "const char* + const char*" is illegal.
(Also, is this something that I could add myself? By developing another + operator for string?)
string f = "F" + "F"; "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>> So I guess to answer my own question, 'yes, I missed something'
Yes, but it's an easy mistake to make. Since string literals are of type const char *, and it's not possible to overload built-in data types, "F" + "F" is trying to add two addresses, which is an ambiguous, and thus, illegal, operation.
>> correct?
That would work, but a somewhat more concise method is:
or
since the + operator allows the string object on either side of the expression.
Yes, but it's an easy mistake to make. Since string literals are of type const char *, and it's not possible to overload built-in data types, "F" + "F" is trying to add two addresses, which is an ambiguous, and thus, illegal, operation.
>> correct?
That would work, but a somewhat more concise method is:
C Syntax (Toggle Plain Text)
std::string("F") + "F"
C Syntax (Toggle Plain Text)
"F" + std::string("F");
![]() |
Similar Threads
- STL vector - deleting the last element (C++)
- Need help writing my own reverse iterator class (C++)
- Debian linux c++ development (*nix Software)
- funding great software developers to be successful entrepreneurs (IT Professionals' Lounge)
- Array limit (C)
Other Threads in the C Forum
- Previous Thread: Image Not Showing
- Next Thread: help on char pointers
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






