473,770 Members | 5,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error : undefined reference to

57 New Member
im getting an error and I dont know why can anyone help.

this is the error......

Expand|Select|Wrap|Line Numbers
  1. /tmp/ccxaenRY.o(.text+0x375): In function `main':
  2. : undefined reference to `average_quizes(records, float&)'
  3. collect2: ld returned 1 exit status



Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. ifstream in_file;
  9. //class that holds student record information.
  10. class records{
  11. private:
  12. string name;
  13. float quizes[7];
  14. float projects[6];
  15. float exams[2];
  16. float labs[14];
  17. public:
  18. void set_name(ifstream& in_file);
  19. void set_quizes(ifstream& in_file);
  20. void set_projects(ifstream& in_file);
  21. void set_exams(ifstream& in_file);
  22. void set_labs(ifstream& in_file);
  23. float get_quizes(int val);
  24. //float get_projects(int val);
  25. //float get_exams(int val);
  26. //float get_labs(int val);
  27.  
  28.  
  29. };
  30.  
  31.  
  32. void average_quizes(records,float&);
  33.  
  34. int main()
  35. {
  36.  
  37.  
  38. cout.width(10);
  39. cout << "No." << " " << "Name" <<" " << " " << " Quiz" << " " << "Project" << " " << "Exam" << " " << "Lab" << " " << "Total" << " " << "Grade" << endl;
  40. cout << "---------------------------------------------------------------" << endl;
  41. cout << endl;
  42.  
  43.  
  44.  
  45. records grades;
  46. ifstream in_file;// Define a file input stream and open the file
  47. in_file.open("record.txt"); //opening file
  48.  
  49. if (in_file.fail())
  50. {
  51. // Failed to open the file (file doesn't exist or isn't readable)
  52. cout << "Could not open file: "<< "\n";
  53. exit(1);
  54. }
  55.  
  56.  
  57. int counter = 1;
  58. float quiz_average = 0;
  59.  
  60. while(in_file)
  61. {
  62. average_quizes(grades,quiz_average);
  63. cout << quiz_average;
  64. cout << counter;
  65. }
  66.  
  67. return 0;
  68.  
  69. }
  70. void records::set_name(ifstream& in_file)
  71. {
  72. in_file >> name;
  73. }
  74. void records::set_quizes(ifstream& in_file)
  75. {
  76.  
  77. for (int i = 0; i < 7; i++)
  78. {
  79. in_file >> quizes[i];
  80. }
  81. }
  82. void records::set_projects(ifstream& in_file)
  83. {
  84. for (int i = 0; i < 6; i++)
  85. {
  86. in_file >> projects[i];
  87. }
  88. }
  89. void records::set_exams(ifstream& in_file)
  90. {
  91. for (int i = 0; i < 2; i++)
  92. {
  93. in_file >> exams[i];
  94. }
  95. }
  96. void records::set_labs(ifstream& in_file)
  97. {
  98. for (int i = 0; i < 14; i++)
  99. {
  100. in_file >> labs[i];
  101. }
  102. }
  103. //accessing quiz values.
  104. float records::get_quizes(int val)
  105. {
  106.  
  107. if(val < 7)
  108. return quizes[val];
  109. else
  110. return quizes[0];
  111.  
  112. }
  113. //printing out quizes.
  114. void average_quizes(records* obj,float& quiz_average)
  115. {
  116. for (int i = 0; i < 7; i++)
  117. {
  118. obj-> get_quizes(i);
  119. quiz_average = i + quiz_average;
  120. quiz_average = (quiz_average/7);
  121. }
  122. }
May 14 '07 #1
7 3644
ilikepython
844 Recognized Expert Contributor
im getting an error and I dont know why can anyone help.

this is the error......

Expand|Select|Wrap|Line Numbers
  1. /tmp/ccxaenRY.o(.text+0x375): In function `main':
  2. : undefined reference to `average_quizes(records, float&)'
  3. collect2: ld returned 1 exit status



Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. ifstream in_file;
  9. //class that holds student record information.
  10. class records{
  11.      private:
  12.         string name;
  13.         float quizes[7];
  14.         float projects[6];
  15.         float exams[2];
  16.         float labs[14];
  17.      public:
  18.         void set_name(ifstream& in_file);
  19.         void set_quizes(ifstream& in_file);
  20.         void set_projects(ifstream& in_file);
  21.         void set_exams(ifstream& in_file);
  22.         void set_labs(ifstream& in_file);
  23.         float get_quizes(int val);
  24.         //float get_projects(int val);
  25.         //float get_exams(int val);
  26.         //float get_labs(int val);
  27.  
  28.  
  29. };
  30.  
  31.  
  32. void average_quizes(records,float&);
  33.  
  34. int main()
  35. {
  36.  
  37.  
  38.     cout.width(10);
  39.     cout << "No." << "  " << "Name" <<"  " << "  " << " Quiz" << "  " << "Project" << "  " << "Exam" << "  " << "Lab" << "  " << "Total" << "  " << "Grade" << endl;
  40.     cout << "---------------------------------------------------------------"         << endl;
  41.     cout << endl;
  42.  
  43.  
  44.  
  45.         records grades;
  46.         ifstream in_file;// Define a file input stream and open the file
  47.         in_file.open("record.txt"); //opening file
  48.  
  49.         if (in_file.fail())
  50.         {
  51.         // Failed to open the file (file doesn't exist or isn't readable)
  52.         cout << "Could not open file: "<< "\n";
  53.         exit(1);
  54.         }
  55.  
  56.  
  57.         int counter = 1;
  58.         float quiz_average = 0;
  59.  
  60.         while(in_file)
  61.         {
  62.         average_quizes(grades,quiz_average);
  63.         cout << quiz_average;
  64.         cout << counter;
  65.         }
  66.  
  67.         return 0;
  68.  
  69. }
  70. void records::set_name(ifstream& in_file)
  71. {
  72.         in_file >> name;
  73. }
  74. void records::set_quizes(ifstream& in_file)
  75. {
  76.  
  77.         for (int i = 0; i < 7; i++)
  78.         {
  79.                 in_file >> quizes[i];
  80.         }
  81. }
  82. void records::set_projects(ifstream& in_file)
  83. {
  84.         for (int i = 0; i < 6; i++)
  85.         {
  86.                 in_file >> projects[i];
  87.         }
  88. }
  89. void records::set_exams(ifstream& in_file)
  90. {
  91.         for (int i = 0; i < 2; i++)
  92.         {
  93.                 in_file >> exams[i];
  94.         }
  95. }
  96. void records::set_labs(ifstream& in_file)
  97. {
  98.         for (int i = 0; i < 14; i++)
  99.         {
  100.                 in_file >> labs[i];
  101.         }
  102. }
  103. //accessing quiz values.
  104. float records::get_quizes(int val)
  105. {
  106.  
  107.         if(val < 7)
  108.         return quizes[val];
  109.         else
  110.         return quizes[0];
  111.  
  112. }
  113. //printing out quizes.
  114. void average_quizes(records* obj,float& quiz_average)
  115. {
  116.         for (int i = 0; i < 7; i++)
  117.         {
  118.             obj-> get_quizes(i);
  119.             quiz_average = i + quiz_average;
  120.             quiz_average = (quiz_average/7);
  121.         }
  122. }
I think it is because your prototype is different from your declareation:
Expand|Select|Wrap|Line Numbers
  1. void average_quizes(records,float&);
  2. void average_quizes(records* obj,float& quiz_average)
You ask for a pointer in one and an actual object in the other.
You can overload a function by the type of arguements are passed to it. So the compiler sees the function, but doesn't see the actual body. The one you gave it is not looked for because it takes a pointer. Try changing one of them and see what happens.
May 14 '07 #2
gdarian216
57 New Member
i changed that and now I got this


test.cpp: In function `int main()':
test.cpp:63: error: cannot convert `records' to `records*' for argument `1' to `void average_quizes( records*, float&)'
May 14 '07 #3
ilikepython
844 Recognized Expert Contributor
i changed that and now I got this


test.cpp: In function `int main()':
test.cpp:63: error: cannot convert `records' to `records*' for argument `1' to `void average_quizes( records*, float&)'
Ok, that means you are passing a "records" when you should pass a pointer to one. You can either pass a pointer or change the function to take an actual object instead of a pointer.
May 14 '07 #4
gdarian216
57 New Member
I thought I was passing a pointer. What did I do wrong
May 14 '07 #5
ilikepython
844 Recognized Expert Contributor
I thought I was passing a pointer. What did I do wrong
You weren't passing a pointer. Add an ampersand in front of the variable or make it a pointer. Do you know how to do that?
May 14 '07 #6
gdarian216
57 New Member
do u mean something like this

void get_score(recor ds&,float&)

but that would pass it by reference.

how would I make it a pointer?
May 14 '07 #7
ilikepython
844 Recognized Expert Contributor
do u mean something like this

void get_score(recor ds&,float&)

but that would pass it by reference.

how would I make it a pointer?
No, no. The way you are calling the function is the problem. You are passing in an object of "records" type. You need a pointer to the location of that object. To do that add an ampersand in front of the variable grades in your function call.
Like this:
Expand|Select|Wrap|Line Numbers
  1. average_quizes(&grades, quiz_average);
  2.  
Post here if you are having problems.
May 14 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5309
by: skubik | last post by:
Anyone else have this problem compiling PHP 4.3.3 from source under Linux (I'm using Slackware 9.0)? Under PHP 4.3.2 I had no compilation problems at all, but now all of the sudden, compiling with GD support gives me the list of errors below. My ./configure is: ../configure --with-pgsql=/usr/local/pgsql --with-ssl=/usr/local/ssl --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-zlib-dir=/usr/lib
2
13125
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on Unixware/C++/AT&T componets environment. I have been able to compile all modules after making necessary changes in LINUX/gcc/STL environment. We have two templates defined XList and XMap.
1
7791
by: Hardy | last post by:
Hi, just come into the boost world. just the first.cpp in the program_options examples, with many link error... devc++4.9.9.2, gcc 3.4.2, can I get your opinions on this problem? thank you~ make.exe -f "D:\temp\Makefile.win" all g++.exe -c main.cpp -o
1
2331
by: Jean-Christian Imbeault | last post by:
On my RH 9.0 linux system when ./configuring 7.3.4 I get an error about not finding the readline libs, however both the readline and readline-devel rpms are installed: # rpm -qa | grep readline readline-4.3-5 readline-devel-4.3-5 What library/rpm am I missing?
1
2107
by: Robert Fitzpatrick | last post by:
I am getting the following problem with trying to install from source PHP 4.3.6 with PG support on FreeBSD 5.2.1. I have PostgreSQL 7.4.2 recently upgraded from 7.3.x and it is up and running fine. I also have Heimdal 0.6 installed and PostgreSQL was built with that support. Is the error below from something missing on the Heimdal side of things or PostgreSQL? And what does anyone suggest to resolve the issue? Maybe I need to rebuild...
4
3043
by: yogesh | last post by:
mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... #include <stdio.h> #include <mysql.h> #include <string.h> int main() {
4
2221
by: sublimanized | last post by:
Hello all ... here is my problem. I just got the book "Teach Yourself C ++ in 21 Days" Setup: Fedora Core 6 - i386 GCC 4.1.1 Again, I am a complete newcomer to C++, and this is one of the first examples out of the book. I want to know why exactly this doesn't clean compile, and how would i fix it?
3
11601
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE -DTRACING - D__EXTENSIONS__ -D__RWCOMPILER_H__ -D_REENTRANT -D_RWCONFIG=8s - D_RWCONFIG_12d -D_RWSTDDEBUG -DRWDEBUG -o test1 test1.o -L/lib -
0
2751
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
3
3274
by: singhPrabhat | last post by:
I have some .c and .h files in my directory. My aim is to compile the whole file. I am compiling each and every .c file by gcc -c file_name then I use gcc -o some_text file_name. I have found out that some file starts with #ifdef UNIX. But UNIX is nowhere defined in either header file(.h file) it includes not in the file itself. For the time being I am defining as #include UNIX in the file whereever required. some of the files...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.