![]() |
| ||
| Help with creating a class Hello everyone I have to create a class that has the following: Quote:
This is what is in my header file: class Field{This is what I have in my cpp file: // Field Class functions 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. |
| ||
| Re: Help with creating a class // Star is in the wrong placeThe 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: void *Field::data(){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: #include <iostream> |
| ||
| Re: Help with creating a class Well No Wonder You are getting errors. This is because you have declared a void function and giving a return value to it. |
| ||
| Re: Help with creating a class Thanks for that information! Although when I compile that example program I get an error saying "pure specifier on function definition" on this line: virtual ~Field() = 0 {} |
| ||
| Re: Help with creating a class Sorry, Edward was accidentally using a Visual Studio extension. This should work: #include <iostream> |
| ||
| Re: Help with creating a class I see thanks! |
| All times are GMT -4. The time now is 10:29 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC