The c_str() is what is flagging an error. It says that in class "Mystring" there is no member for "c_str".
Which means I need to have it in my class to function, I am just unsure what to change to have it work correctly.
What is the error you run into? The purpose of a move constructor is to extract the contents of the mystring&& object into the object being created. It repurposes the pointer instead of copying the contents of what the pointer points to, thereby being more efficient. The mystring&& object should no longer be used afterwards, and will be destroyed when it goes out of scope.
PPS: I can almost guarantee you that it's bad practice for your generic Mystring class to have to be 'friends' with a specific class like Potion. You shouldn't have to do something like that. You should let the necessary functionality of your string be exposed through functions, just like how std::strings don't need to be friends with a Potion to be useful.
The default operator()= is not suitable when dynamic memory is used (as here). Hence the =delete to prevent run-time issues. If = is required, then a proper implementation for the operator=() function needs to be implemented.
This is quite easy to implement. In my code above replace L15-16 with:
Thank you for the resource, I will read up on noexcept and try to become more familiar with the operators. I do not fully understand your explanations, but I am fairly new to constructors/destructors and classes. So reading up on those will do me good.
Got it working correctly I think. At least the output is what I want.
I was receiving LINK 2005 errors, so I tried placing all of MyString functions inside the class instead of defining them outside of it. That seemed to work.
I also needed to place my char * str in public and not private so everything could access it.
heh we just had a discussion about that. Making stuff private just so you have to write getters and setters .. be practical was what most people said. Purism would demand that you do that (private with accessors) but purist code isnt practical for all things. Making the variable public is fine if you are willing to own the consequences (mostly, a user fooling with the variable directly in bad ways, eg setting it to nullptr and leaking memory that should have been deleted first for a simple example).
and, also, depends on if this is homework (what is your professor going to want) or learning (did you learn what you wanted from it) or whatever? I am going out on a limb and assuming its not useful (c++ has a better string built into it, no offense :) )
If you needed access to the str as a type const char* to pass as a pointer to another function (eg strcpy), then the way to do this is to provide a custom type overload within the class (or as a separate function as per Ganado's post above):