I was executing this programe and received error at line 34 saying "name lookup of changed for ISO 'for scoping [-fpermissive]". I am beginner. the code is to prevent buffer overflow when string constant with too long charcters is used. can anyone help me?
#include<iostream>
#include<cstring>
usingnamespace std;
#define n 80
class String{
protected:
char *str;
public:
String(){
//Instantiating String
str = newchar[n];
}
String(char *s){
//Allocate Memory w.r.t the size of parameter string i.e. char *s
str = newchar[strlen(s)+1];
str = s;
}
void Display(){
cout << str << endl;
}
};
class Pstring : public String{
public:
Pstring(char *s){
str = newchar[n+1];
str[n] = '\0';
//Checking for Length
if(strlen(s) <= n)
str = s;
elsefor(int i=0;i<n;i++)
str[i] = s[i];
};
};
int main()
{
//Instantiating
char *title = (char *)"This is a small string!";
//Testing Base Class
String bobj = title;
Pstring pobj = title;
Pstring pobj2 = (char *)"This is a very long string and this string should be trim by the checks I implemented in the constructor!";
//Displaying String
bobj.Display();
pobj.Display();
pobj2.Display();
cout << endl;
cin.ignore();
return 0;
}