Calling a function from an outside file

I m trying to call a function from a *.cpp file that exist in an other *.cpp file, an using a *.h file, but it still does not work.
this is my useContact.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "Contact.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


		cout<<"\t\tMake your choice "<<endl;
		cout<<"\t-1- Add Client"<<endl;
		cout<<"\t-2- Find Client"<<endl;
		cout<<"\t-3- List Client"<<endl;
		cout<<"\t-4- Quit"<<endl;
			cin>>op;
		cin.ignore();
		switch(op){
			case 1: 
				cout<<"\t\tAdd Client"<<endl;
					addContact();
				break;
.........

here is my Contact.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Contact.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void addContact(){
		string fname;
		string name;
                cout<<"First Name: "; cin>>frame;
                cout<<"Last Name: "; cin>>frame;
}

and this is my Contact.h
1
2
3
4
5
6
7
8
9
10
#ifndef CONTACT_H
#define CONTACT_H
#include <iostream>

using namespace std;
class Contact{
	public: 
		void addContact();
};
//endif 

I checked other forums, and it seams that is is working for them.
i keep getting this error message from my compiler:

1
2
useContact.cpp:38:6: error: use of undeclared identifier 'addContact'
                                        addContact();

i tried everything , but still same problem !!
1
2
3
4
5
6
7
class Contact
{
  public:
    void addContact();
  ...

};


1
2
3
4
5
#include "Contact.h"
void Contact::addContact()
{
  ...
}


I'm not sure what you're doing with
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
include "Contact.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


		cout<<"\t\tMake your choice "<<endl;
		cout<<"\t-1- Add Client"<<endl;
		cout<<"\t-2- Find Client"<<endl;
		cout<<"\t-3- List Client"<<endl;
		cout<<"\t-4- Quit"<<endl;
			cin>>op;
		cin.ignore();
		switch(op){
			case 1: 
				cout<<"\t\tAdd Client"<<endl;
					addContact();
				break;
.........

There's no function there. Is that supposed to go in main?

Do you have multiple "Contact.h" files? You should only have 1.
I have only one file Contact.h, one useContact.cpp(which is my main function), and one Contact.cpp
I am just trying to call the addContact() function that exist in Contact.cpp. but it doesn't even recognize it
main.cpp should have your main function, not useContact.cpp.

Contact.h
1
2
3
4
5
6
7
#ifndef CONTACT_H
#define CONTACT_H
#include <string>
#include <iostream>

void addContact();
#endif 


Contact.cpp
1
2
3
4
5
6
#include "Contact.h"

void addContact()
{
  ...
}


Is addContact supposed to be part of a class? Is it supposed to change some object and add contact info to something else? Currently it doesn't look like it would do that.
Topic archived. No new replies allowed.