c++ - Implicitly convert from std::string to eastl::string -


i using string class stl std::string want replace eastl. easy question:

eastl::string obj = std::string("test"); 

error: conversion ‘the::string {aka std::basic_string}’ non-scalar type ‘eastl::string {aka eastl::basic_string}’ requested

is possible automate conversion between types?

no, not if eastl::string not define copy constructor/assignment operator std::string.

the simplest way go std::string eastl::string use .c_str() method pointer std::string's internal char array

std::string ss("hello"); eastl::string es = ss.c_str();  

you can add own if want modify library. although bad idea

simple example:

class mystring {     private:         char *str;     public:         mystring(const std::string &s) {             str = new char[s.length() + 1]; /* allocate */             strcpy(this->str, s.c_str());   /* copy */         }         ~mystring() {             delete [] str;         } }; 

then can create new mystring with:

mystring ms = std::string("hello"); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -