How to assign char array as user define string object

STRING s1 = “FOOBAR”

Here STRING is a user defined class. how to assign a constant char array "FOOBAR" to string object? Copy constructor need to be same class type as parameter. and overloading assignment operator also need to be same class type. I think 'friend' can let pass another type of object rather than STRING to do operation on overloaded '=' operator. How could it be done if it is possible at all?
That line you've written doesn't invoke the assignment operator. It invokes the constructor. Specifically, it invokes a constructor with with signature STRING(const char*).

So write that constructor :)
1
2
SomeType SomeName = SomeExpression; //initialization -> constructor call
         SomeName = SomeExpression; //assignment -> operator= 
Last edited on
Topic archived. No new replies allowed.