I'm creating a system that has 7 categories of data (thus, 7 different objects) that users can add, edit and delete from. To be more efficient, I made a utility class extending from that defines add, edit and delete functions more specific to the program. Because the user can input data in the Add function, I'm passing a class member function pointer into List's addObject class that inputs the data specific for that object. Thus, the List class adds the object and each class has a class member function for their specific variables.
I have this error in the addObject class:
Called object type 'bool (Product::*)()' is not a function or function pointer
it seems like the List class can't access the Product data. When I added #include "Product.h" in the head, the compiler sent many errors about double initialization of Product functions, which is very odd because ALL classes have #ifndef, #define and #endif at top and bottom respectfully.
Here's my code - I added what I think is important for understanding, so let me know if you need more to understand:
Main:
#include <list>
#include <iterator>
#include <algorithm>
#include "Product.h"
#include "List.h"
int main ()
{
bool (Product::*prodFunc) () = &Product::addProduct;
allProducts.addObject(allProducts.back(), prodFunc);
}
in the List Class:
template<class DT>
bool List<DT>::addObject(DT & previous, bool (DT::* func)())
{
bool success = true;
int newID = 1 + (previous.getID());
cout << "New ID: " << newID << endl;
previous.setID(newID);
func(); //Error here
return success;
}
Product's addProduct class:
bool Product::addProduct()
{
bool success = true;
cout << "Please enter the following for your new product:\n";
addItem();
return success;
}
I'm sure (or at least hope) it's something real simple that I'm missing. Thanks!
func(); //Error here-- Hint -- When you call a member function by pointer, you need an object specified somewhere in the call. Where is the object in that call?