Im trying to call a function in C++ and I thought it would be the same as in C, but when trying to convert a C program to C++ I’ve run into an error where it says functions are undeclared.
Here is my class:
class contacts
{
private:;
char *First_Name;
char *Last_Name;
char *home;
char *cell;
public:;
//constructor
contacts()
{
}
//Function declaration
void readfile (contacts*friends ,int* counter, int i,char buffer[],FILE*read,char user_entry3[]);
};
Here is a snippit of my Menu function:
if(user_entry1==1)
{
printf("Please enter a file name");
scanf("%s",user_entry3);
read=fopen(user_entry3,"r+");
//This is the "undeclared" function
readfile(friends ,counter,i,buffer,read,user_entry3);
}else;
I’m obviously doing something wrong, but every time I try and compile I get readfile undeclared(first use this function) What am I doing wrong here?
Is the “Menu” function from inside the class
contacts? The way you have designed it, it can be only called on an instance of the the class. You have options based on exactly whatreadfilemeans tocontactsIm guessing the function reads all contacts and not just 1 contact, which means it can be made a static function
And call as
Alternatively if you dont need direct access to internals of the class you can just declare it outside the class (as a free function, similar to normal C functions) and use exactly as you are doing now. This is in fact what the compiler is searching for when it comes across your code.
Also, I suggest you rename
class contacts->class contactsince it appears that objects each holds the contact information of only 1 person.