Hello everyone I have to create a class that has the following:
Quote ...
Your Field class is the base class from which you will derive all other Field classes.
Your Field class has the following public member functions, all of which are virtual:
* void display() - does nothing here, but will display the field in derived classes.
* int edit() - does nothing here and returns 0, but will edit the field in derived classes.
* bool editable() const - returns false here, but will return the editability of the field in derived classes.
* void *data() - returns NULL here, but will return the address of data stored in the field in derived classes.
* Field *clone() const - returns NULL here, but will create a clone of the field in derived classes.
I would like some input if I did the above correctly.
I am getting errors with what I currently have and decided to break it down piece by piece. I would like to know if what I did is correct, any input is highly appreciated.
// Star is in the wrong place
void Field::*data(){
return NULL;
}
// Star is in the wrong place
// void* is the wrong return type
void Field::*clone() const{
return NULL;
}
The class name and scope operator go right next to the method name, after the return type. You just need to move the star over a bit. In your class you say that clone() returns a Field* too:
Make sure you include a header that defines NULL, like <cstddef>, or that might cause an error too.
On a design note, the entire Field class should be abstract because it's a base class. That saves you the need to implement dummy methods that don't do anything but return a useless value. A good rule of thumb is to make any base class abstract and only leaf classes concrete. That way you don't have to worry about problems like slicing. Also, if you plan on using Field polymorphically, a virtual destructor is a good idea:
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.