Question:
C++ Undefined references?
Tj
2013-01-24 14:46:35 UTC
so this is a segment of my program, i am having trouble calling the the functions and i really need some help. What am doing wrong ?please help, i keep getting "[Linker error] undefined reference to `Customer_Record()'" , [Linker error] undefined reference to `Car_Record()' and ld returned 1 exit status THANK YOU IN ADVANCE

CODE:

#include
#include
#include
#include
#include

int Customer_Record(void),Car_Record(void);
int num;


struct Customer
{
char customer_ID[20];
int license;
char address[20];
int phone;
char email[20];
}cust ;


struct car
{
int regno[20];
char model[20];
char colour[10];
}car;

main(){

printf (" Enter 1 to go to Customer Record \n\n");
printf (" Enter 2 to go to Car Record \n\n");

scanf ("%d", &num);
if (num = 1)
{
Customer_Record();
}
else
if (num = 2)
{
Car_Record();
}
else
{
printf("Invalid Number");
}


void Customer_Record();
{
printf("********CUSTOMER RECORD********");
printf("\nEnter the name of the customer ");
scanf ("%s", &cust.customer_ID);
printf("Enter the license number of the customer ");
scanf ("%d",&cust.license);
printf("Enter the address of the customer ");
scanf ("%s",&cust.address);
printf("Enter the cell phone number of the customer ");
scanf ("%d",&cust.phone);
printf("Enter the email address of the customer ");
scanf ("%s",&cust.email);
}



Car_Record();
{
printf("********CAR RECORD********");
printf("\nEnter the car's registration number ");
scanf ("%d",&car.regno);
printf("Enter the car's model ");
scanf ("%s",&car.model);
printf("Enter the colour of the car ");
scanf ("%s",&car.colour);
}
getchar();
getchar();
}
Three answers:
Richard K
2013-01-24 14:51:49 UTC
You are declaring two functions of type int: int Customer_Record(void),Car_Record(void);



and later on you are defining two functions of the same name, one with type void, the other has no type (illegal).



To correct this, make the function declaration's EXACTLY the same as the function definition.



For example:



//Declare there is an add function that has two int parameters and returns an int somewhere in the code (a promise to the compiler)

int add(int a, int b);



//Some code here



//Define the add function EXACTLY as Declared above (make good on the above promise to the compiler so the linker doesn't bit*h us out later on!)

int add(int a, int b)

{

return a+b;

}



Remember when you are making a function declaration, you are telling the compiler that even though you are going to be using a function that hasn't been defined yet, it will at some point, if not in the same file, than some other file.



If you don't make good on that promise, the code WILL compile but when it comes time to link function use to function code, the linker will freak out because it can't find the function code! And the linker is VERY strict, if you typo a function's name, or get the type's incorrect, it won't even see a connection between the two! This is why you make sure both declaration and definition are exactly the same!



Hope that helps :)
BrkinDwn10ChknsDwg
2013-01-24 14:54:40 UTC
For programming help, you'll have a lot better luck posting your questions at www.stackoverflow.com.



Trust me. You'll be happy you joined.
quiles
2017-01-11 21:46:07 UTC
contain header for sophistication B in the previous using in college A. although, this technique will artwork. // Header record classification B; classification A { public: void addB(B *); ... }; classification B { public: int getResult(); ... } // source record void A::addB(B *b) { int bresult = b->getResult(); ... } which could favor to fix your project.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...