Thread: Function pointers

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    Function pointers

    I keep on getting this error in BCC32

    Error E2285 a3main.cpp 149: Could not find a match for 'TextField::TextField(int
    ,int,int,char *,int,void,Field *)' in function mainScreen::mainScreen()

    and on the Unix AIXC:

    "a3main.cpp", line 137.18: 1540-0286 (W) The unqualified member "isName" should be qua
    lified with "::" and preceded by an "&" when forming an expression with type pointer-t
    o-member.
    "a3main.cpp", line 137.18: 1540-0216 (S) An expression of type "bool (mainScreen::*)(T
    extField *, Field *)" cannot be converted to "bool (*)(TextField *, Field *)".

    basically due to this code:
    Code:
    class mainScreen{
    
        //record r1;
    	//to keep track of number of records
    	int recordCount;
        fstream _f;
        streampos end;
    	Screen _mainS;
        enum{ ID,Name,A1,A2,A3,Mid,Final,Letter,Comments,Overall,Active1,Active2,Active3,Active4,Active5};
        int _flds[15];
        int _msgs[9];
    	Field msgField;
    	TextField txtStudId;
        //The Client does not need to access the list
    	struct node
    	{
    		record r;
    		int recNumb;//so the student record number will be known
    		node *next;
    		node *prev;
    
    		node(record n,int rn,node *nn=NULL,node *pn=NULL):r(n),recNumb(rn),next(nn),prev(pn){}
    	};
    	
    	node *Records;
    	//The current record
    	node *currentRecord;
    	//if update is true the text file is updating a record
    	//else it is just appending
    	bool writeToFile();
    	bool readFromFile();
    	//go to next node       
    	bool goNext();
    	bool goPrev();
    	void changeFields();
    	int search(bool SearchName);
    	double nV;
    	
    	void updateRecord();
    	//To get the Average grade per assignment/test and get the total of each
    	void getAverages(double *GradeList,int *CountList);
    	double calcGrade();
    		bool (*isValidN)(TextField *,Field *);
    		bool isName(TextField *txt, Field *msg);
    	public:
    		
    		mainScreen();
    		int edit();
    		
    
    		~mainScreen();
    		
    };
    /*create all the fields */
    mainScreen::mainScreen():msgField(24,2,70,""),txtStudId(4,15,10," ",9,isID,&msgField),Records(NULL){
    	
    	
    	....
    	
    	_mainS.addField(new Label(6,2,"Student Name: "));
    	_flds[Name]=_mainS.addField(new TextField(6,17,30,currentRecord->r.studName,30,isName,&msgField));
    --->The constructor takes a bool (*isValid)(TextField *,Field *) function pointer(this works when the function is not declared in the class, but I need to declare it inside to do something)
    	_msgs[Name]=_mainS.addField(new Field(7,2,30,""));
    	
    	}
    
    
    
    
    //Validation functions
    
    ...
    
    
    //checks name
    bool mainScreen::isName(TextField *txt, Field *msg) {
        bool ok = true;
        if (txt->getLength() == 0) {
    	ok = false;
    	if (msg != NULL) {
    	    msg->setData("Enter Student Name");
    	    msg->display();
    	}
        } else {
    	char *name = new char[txt->getLength() + 1];
    	txt->getData(name);
    	for(int i=0;name[i]!='\0';i++){
    		
    			if(i==0 && isalpha(name[i]) || name[i-1]==' ')
    				name[i]=toupper(name[i]);
    			else
    				name[i]=tolower(name[i]);
    			
    		}
    	txt->setData(name);
    	delete [] name;
        }
    	
        return ok;
    }
    ....
    
    
    int main()
    {
    	
    	mainScreen mS;
    	mS.edit();
    	
    	return 0;
    }
    any ideas would be appereciated, thank you
    Last edited by rmlove; 12-07-2003 at 10:41 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  2. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  3. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. function pointers and member functions
    By thor in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2002, 04:22 PM