Im making a class that is supposed to be able to assign c-strings the same way the string class i able to:
string a = "My string";
The issue I’m having is that it seams like it is not the operator=( char operand ) that is used for this purpose. So my question is this: What is used instead?
What I have:
class exstring
{
...
public:
exstring& operator=( char* );
...
};
...
int main()
{
exstring test = "test";
}
Which gives:
main.cpp:9:22: error: conversion from ‘const char [19]’ to non-scalar type ‘std::exstring’ requested
Any ideas?
You are not calling your
operator =here. You need to learn the difference between assignment and initialization. What you’re doing is initialization and you need a constructor that takes the parameter you’re providing. In other words:Is exactly the same as:
Except that in the latter case the constructor could be explicit, but not in the former.