class User
{
protected:
int *ID;
public:
User();
User(int *id){
setID(id);
}
~User(){};
staticvoid setID(){
int ID;
cout<<"Enter ID: ";
cin>>ID;
}
void setID(int *id){
ID=newint[strlen(id)+1];
strcpy(ID,id);
}
void *getID(){
return ID;
}
};
class Members: public User
{
public:
staticvoid DeleteMember(){
cout<<"Deleting member information! Please wait...."<<endl;
delete ID;
}
};
int main()
{
Members::DeleteMember();
getch();
}
When i try to compile this piece of code it gaves me these errors:
In static member function `static void Members::DeleteMember()':
invalid use of member `User::ID' in static member function
from this location (Line 30)
You have a lot of errors in that code, and I don't even know why you treat a pointer to an integer as if it were a string! (lines 18 and 19). This cannot even compile, and if your compiler is compiling it, dump that compiler for one that works. Nothing good can come out of it.
As pointed out, DeleteMember() is static and cannot access ID. Also in main() you are trying to delete an object, but you never create one in the first place. The overloaded setID() that is static tries to access the ID variable that isn't static.
Besides what other users mentioned you are trying to delete an unallocated variable (ID) inside main(). Not a good thing to do.
And besides that you are trying to delete it with the wrong command:
You are using new[] so you must use delete[] to delete it, not delete (the latter just deletes the first element of the array).