I ve to add strings using + operator. I am using strcat function to add and I am getting following error
In function ‘int main()’:
cppfirst.cpp:44: warning: deprecated conversion from string constant to ‘char*’
cppfirst.cpp:44: warning: deprecated conversion from string constant to ‘char*’
cppfirst.cpp:48: error: invalid operands of types ‘char*’ and ‘char*’ to binary ‘operator+’
#include<iostream>
#include<cstring>
#include <string.h>
using namespace std;
Try using proper, grown-up C++ strings. You can use these with the <string> header. The <string.h> header is a C header and does not give you proper C++ strings.
Your function getst1 and getst2 return char*, so String.getst1()+String.getst2(); is an attempt to use the '+' operand with 2 char* objects. This cannot be done.
The '+' operand you defined works on two of your str class, so try using it on your str class rather than on two char* objects.