i want to overload the assignment operator such that it will be used to assign data at the time of initialization of object
for initializing a string object we can follow the format given below
string str = "Hello World !!!";
but it will be a error if we define our object in same manner;
for example
#include<iostream>
using namespace std;
class Name{
private:
string name;
public:
Name(){}
Name(string str){
name=str;
}
};
int main(){
Name name="Jack";
}
it is showing error like
E:\Documents\test.cpp||In function 'int main()':|
E:\Documents\test.cpp|13|error: conversion from 'const char [5]' to non-scalar type 'Name' requested|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
so how to make a class such that it can accept data like string object .