I am not sure why this is occuring. I declared these functions in the header file and it is defined them in the .cpp file but in the main function it does not recognize them. Did I forget something basic or do something illegal?


The errors:
: error C3861: 'createAndInitializeTextFile': identifier not found
: error C3861: 'enterRecords': identifier not found
: error C3861: 'test': identifier not found
: error C3861: 'test': identifier not found
: error C3861: 'processChoice': identifier not found


My code for the header file:

class Tools
{
public:
	Tools(int = -1, string = "", int = 0, double = 0.0);	
	void setPartNumber(int);
	int getPartNumber() const;

	void setToolName(string);
	string getToolName() const;
	void setInStock(int);
	int getInStock() const;
	void setUnitPrice(double);
	double getUnitPrice() const;

	void createAndInitializeTextFile();
	void enterRecords();
	bool test();

	void processChoice();
	int enterChoice();

	void printTextFile(fstream&);
	void updateRecord(fstream&);
	void newRecord( fstream& );
	void deleteRecord( fstream& );
	void outputLine( ostream&, const Tools & );
	int getPart( const char * const );

private:
	enum Choices { PRINT = 1, UPDATE, NEW, DELETE, END };
	int partNumber;			
	char toolName[20];		
	int inStock;		
	double unitPrice;		
};

Some parts of my member function definitions:

void Tools::enterRecords()
{
	 fstream outTools( "hardware.dat", ios::in | ios::out | ios::binary );

    // exit program if fstream cannot open file
    if ( !outTools )
    {
       cerr << "File could not be opened." << endl;
       exit( 1 );
    } // end if

    cout << "Enter tool identification number (1 to 100, 0 to end input)\n? ";

    // require user to specify account number
    Tools tool;
	//cin >> partNumber;

	partNumber = 3;
	cout << " 3";


    // user enters information, which is copied into file
    while ( partNumber > 0 && partNumber <= 100 )
    {
	   // user enters tool name, quantity and unit price
       cout << "Enter the tool name, quantity in stock, and the unit price for the tool\n? ";
       //cin >> setw( 20 ) >> toolName;
       //cin >> inStock;
       //cin >> unitPrice;

	   toolName = "Electric Sander";
	   inStock = 7;
	   unitPrice = 57.98;

       // set the record for the part number, tool name, quantity in stock, and unit price
       tool.setPartNumber( partNumber );
       tool.setToolName( toolName );
       tool.setInStock( inStock );
       tool.setUnitPrice( unitPrice );

       // seek position in file of user-specified record   
       outTools.seekp( ( tool.getPartNumber() - 1 ) * sizeof ( Tools ) );                         

       // write user-specified information in file                   
       outTools.write( reinterpret_cast < const char * >( &tool ),sizeof ( Tools) );     
                             

       // enable user to enter another account
       //cout << "Enter account number\n? ";
       //cin >> partNumber;

    } // end while
}

bool Tools::test()
{
   ifstream inTools( "hardware.dat", ios::in | ios::binary );

    // exit program if ifstream cannot open file
    if ( !inTools )
    {
       cerr << "File could not be opened." << endl;
       exit( 1 );
    } // end if

	Tools tool;

	bool answer = false;
	
	if ( tool.getPartNumber() != 0 )
		answer = true;
	else
		answer = false;

	return answer;
}

My code in .cpp main function, where the error is occurring:

#include "Tools.h"

int main()
{
	createAndInitializeTextFile();
	enterRecords();
	test();

	if(test())
	{
		"Hardware program successful.";
		processChoice();
	}
	else
	{
		"Hardware program failed.";
	}

	cout << endl;
	return 0;
}

Recommended Answers

All 3 Replies

You have a class Tools with these (and others) member functions. Remember a syntax of member function call:

object.member_function_name(parameters)
// or
pointer_to_object -> member_function_name(parameters)

So, for your test (member!) function call you must write, for example:

#include "Tools.h"
...
int main()
{
    Tools tools;
    ...
    tools.test();
    ...
}

Without object specification you try to call free functions (not member functions). Of course, no such functions in your code. Apropos, it's rather suspicious code part:

test();
if (test())
...

Did you really want to call test() twice? Why?

Think again about classes, objects and member functions in C++...

aaww yes I forgot the object! how silly.... thank you. :o)

how to solve this error??

error C3861: 'sql_error': identifier not found

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.