GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Sep-2004, 19:22
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Question

"undefined symbol" error


I've searched on the 'net for this error I didn't find anything that explained it. When I build my program, I get the error (also given as "undefined reference") at the point
CPP / C++ / C Code:
weeksPay (days_worked, pay, HRRATE);
right after I declare the vector<double>pay.

If I click on the actual error, I'm taken into the stl_vector.h file, which doesn't help me. As usual, I don't see anything obvious as to why this particular function call is giving me an error, unless it's related to my using a constant number.

I've check my help files, but this particular error isn't listed. The only thing suggested on other sites is that something is unreadable, but I don't understand why that may be.

CPP / C++ / C Code:
/*******************************************************************************
*Cody Jackson (60-0067CE)
*CS265
*Lab 7
*
*Purpose:  Create a program using the vector class that allows the user to input
*	the number of days worked (out of 7) and, using a fixed hourly rate, calculates
*	the week's wages and average number of hours worked per day.  Assume an 
*	8 hour work day.
 *********************************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include "myVector.h"
using namespace std;

const double HRRATE = 12.00;

void promptAndRead (const vector < string > &personnel,
		    vector < double >&days_worked);

void weeksPay (const vector < double >&days_worked,
	       vector < double >&pay, const double HRRATE);

void avgDailyHours (const vector < double >&days_worked,
		    vector < double >&day_hours);

/*void printResults(ostream& out, double meanScore, 
                  const vector<string>& names, 
                  const vector<double>& scores);
*/
int
main ()
{
	cout << "Enter the name of the personnel file: ";
	string input_file;
	cin >> input_file;

	ifstream fin (input_file.data ());	// open stream to input file
	vector < string > personnel;	// vector array for personnel names
	read (fin, personnel);	//  fill array from input file

	vector < double >days_worked;	// array for days worked
	promptAndRead (personnel, days_worked);	// fill array from standard input

	vector < double >pay;	//array for weekly payroll
	weeksPay (days_worked, pay, HRRATE);

	vector < double >day_hours;	//array for avg hours worked per day
	avgDailyHours (days_worked, day_hours);

	//***DEBUG***
	for (int i = 0; i < personnel.size (); i++)
	{
		cout << "Name:  " << personnel[i] << "\t" << "Days worked:  "
			<< days_worked[i] << "\t" << "Weeks pay:  " << pay[i]
			<< "\t" << "Avg hours per day:  " << day_hours[i] <<
			endl;
	}
	return 0;
	//printResults(cout, meanScore, roster, originalScores);
}

/* promptAndRead() reads a sequence of days from the keyboard and puts them into
*	the days_worked array
 ****************************************************************/
inline void
promptAndRead (const vector < string > &personnel,
	       vector < double >&days_worked)
{
	double days;
	for (int i = 0; i < personnel.size (); i++)
	{
		cout << "Enter the days worked for " << personnel[i] << ": ";
		cin >> days;
		days_worked.push_back (days);
	}
}

/*weeksPay() calculates the weekly pay based on days worked, 
*	assuming on 8 hour day.
*******************************************************************/
inline void
weeksPay (vector < double >&days_worked, vector < double >&pay,
	  const double HRRATE)
{
	for (int i = 0; i < days_worked.size (); i++)
	{
		double wpay = days_worked[i] * 8 * HRRATE;
		pay.push_back (wpay);
	}
}

/*avgDailyHours() computes the average hours worked each day for the week
**********************************************************************/
inline void
avgDailyHours (const vector < double >&days_worked,
	       vector < double >&day_hours)
{
	for (int i = 0; i < days_worked.size (); i++)
	{
		double hours = (days_worked[i] * 8) / 7;
		day_hours.push_back (hours);
	}
}
The header file is attached if needed.
Attached Files
File Type: txt myVector.txt (1.8 KB, 91 views)
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #2  
Old 26-Sep-2004, 20:58
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by crystalattice
I've searched on the 'net for this error I didn't find anything that explained it. When I build my program, I get the error (also given as "undefined reference") at the point
CPP / C++ / C Code:
weeksPay (days_worked, pay, HRRATE);
right after I declare the vector<double>pay.

.


The function prototype:
CPP / C++ / C Code:
void weeksPay (const vector < double >&days_worked,
         vector < double >&pay, const double HRRATE);

doesn't match definition:
CPP / C++ / C Code:
inline void
weeksPay (vector < double >&days_worked, vector < double >&pay,
    const double HRRATE)

first argument must match: const

Note that functions containing "for" are not expanded inline, so the "inline" is ignored, but you must make const vector<double>.....match

Regards,

Dave
  #3  
Old 26-Sep-2004, 21:33
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Asking this in a semi-rhetorical fashion, if the answer is that simple, why can't the error message be more descriptive? Even if it was something along the lines of "mismatched arguments" or something, I could have figured that out. Especially when I'm dumped into stl_vector.h when using my Linux builder. But running it under Metrowerks didn't help; it's help file didn't even have that particular error message.

I have to say, this is probably the biggest thing that pisses me off when programming, heck, even just using computers. Error messages are rarely understandable, if they're in English. (Don't get me started on Windows error messages).

All right, I'm done ranting. Time to get back on topic.

Thanks for the better eyesight.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #4  
Old 27-Sep-2004, 07:32
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by crystalattice
Asking this in a semi-rhetorical fashion, if the answer is that simple, why can't the error message be more descriptive? Even if it was something along the lines of "mismatched arguments" or something, I could have figured that out. Especially when I'm dumped into stl_vector.h when using my Linux builder. But running it under Metrowerks didn't help; it's help file didn't even have that particular error message.

I have to say, this is probably the biggest thing that pisses me off when programming, heck, even just using computers. Error messages are rarely understandable, if they're in English. (Don't get me started on Windows error messages).

All right, I'm done ranting. Time to get back on topic.

Thanks for the better eyesight.


Due to the strict type checking of C++ and the ability to have two functions with the same name but different argument types, arguments of function definitions must exactly match the prototypes.

When you get messages like this, you learn to check this. (At least now you have learned this.) "Undefined symbol" and such things mean different things for different conditions. It is definitely possible for compiler/linker writers to give more explicit error messages, and sometimes I sure wish they would. (Lots of things can cause a linker not to be able to find a missing function; how hard should the linker work to try to find close-but-not-exact matches?)

My favorite error message used to be "Missing semicolon on line 123". My thoughts were, well if you (the compiler) are smart enough to know that, why don't you just put in the bloomin' semicolon? Then, of course I realized that I don't want the compiler to assume anything; the missing semicolin might be a byproduct of some really bad thing that I want to know about. Oh, well...

Regards,

Dave
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Operator Overloading: << aaroncohn C++ Forum 36 07-Dec-2004 19:22
link error? pablowablo C++ Forum 14 19-Jun-2004 10:00
OpenGL always reports error mvt OpenGL Programming 2 04-Jun-2004 06:42
Visual C++ 6 Compiler error vip3r C++ Forum 2 13-Apr-2004 14:34
[script] E-mail webmaster error page BobbyDouglas PHP Code Library 0 19-Aug-2003 20:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:46.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.