HOME       >>       Programming

Vs2008: Error Lnk2019


xboxrulz1405241485

Hey guys I've got some errors. My friend told me it's missing the body of my function. However, my body is obviously there when you look at this post:

pointofsales.h:

#define LIMIT 100void posmath (int *quantity, double *price, char taxable);void initPOS();
stdheader.h:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std;
pointofsales.cpp:
#include "stdheader.h"#include "pointofsales.h"void initPOS(){ cout << "Point of Sales" << endl; cout << "==============\n" << endl; int quantity[LIMIT], intCount = 0; double price[LIMIT]; char taxable[LIMIT]; do { cout << "Quantity: "; cin >> quantity[intCount]; if (quantity[intCount] == 0){ intCount--; break; } cout << "Price: "; cin >> price[intCount]; cout << "Taxable [y/n]: "; cin >> taxable[intCount]; intCount++; } while (intCount <= LIMIT); posmath(quantity, price, *taxable);}
libpos.cpp (not finished):
#include "stdheader.h"#include "pointofsales.h"void posmath (int *quantity, double *price, char *taxable){ int i, tqty = 0; double tprice = 0, sprice = 0, ptax[LIMIT], ftax[LIMIT]; for (i = 0; i <= LIMIT; i++){ tqty += quantity[i]; if (*taxable == 'y'){ ftax[i] = price[i] * 0.05; ptax[i] = price [i] * 0.08; } price[i] = price[i] + ftax[i] + ptax[i]; }}

Build Error:

1>------ Build started: Project: Workshop2, Configuration: Debug x64 ------1>Linking...
1>pointofsales.obj : error LNK2019: unresolved external symbol "void __cdecl posmath(int *,double *,char)" (?posmath@@YAXPEAHPEAND@Z) referenced in function "void __cdecl initPOS(void)" (?initPOS@@YAXXZ)
1>D:\devel\c++\Workshop2\x64\Debug\Workshop2.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:\devel\c++\Workshop2\Workshop2\x64\Debug\BuildLog.htm"
1>Workshop2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is a console application, I tried both compiling it to x86 and x86_64.

Please help?

Thanks,
xboxrulz

turbopowerdmaxsteel

Modify the second line in your pointofsales.h to: void posmath (int *quantity, double *price, char *taxable);. Notice the missing * for the third parameter.

 

You need to do two more changes. Change the 22nd line in pointofsales.cpp to } while (intCount < LIMIT); and line 7 of libpos.cpp to for (i = 0; i < LIMIT; i++){. This will prevent a runtime stack error from throwing up because you are trying to access an element at an index greater than that of the declared arrays' size. If the array was not zero-based like we have in Visual Basic, you would have to check the upper bound with the <= operator and initialize the lower bound with 1. For zero-based arrays it is 0 for the lower and < for the upper bound checking operator.


xboxrulz1405241485

Thanks, I can't believe I made such novice mistakes.I forgot that I was telling it to count more than the LIMIT allows.The compiler should be more specific because the error made no sense to me.Thanks,xboxrulz


xboxrulz1405241485

After added structs, I'm getting LNK2019 errors again. What exactly is this LNK2019 error?

/* pointsofsales.h * Workshop1's Point of Sales header file. * Copyright (C) 2009 Adrien Kwok. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://forums.xisto.com/no_longer_exists/;. * */#define LIMIT 100struct POS{ int quantity[LIMIT]; double price[LIMIT], ftax[LIMIT], ptax[LIMIT], tftax, tptax; char taxable[2];};void posmath(struct POS sales, int *intCount, double *total, double *stotal);void initPOS();

/* pointofsales.cpp * Workshop1's Point of Sales program file. * Copyright (C) 2009 Adrien Kwok. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://forums.xisto.com/no_longer_exists/;. * */#include "stdheader.h"#include "pointofsales.h"void initPOS(){ system("cls"); cout << "Point of Sales" << endl; cout << "==============\n" << endl; struct POS sales; int intCount = 0; double total, stotal; do { cout << "Quantity: "; cin >> sales.quantity[intCount]; if (sales.quantity[intCount] != 0){ cout << "Price: "; cin >> sales.price[intCount]; cout << "Taxable [y/n]: "; cin >> sales.taxable[intCount]; intCount++; } } while (intCount < LIMIT && sales.quantity[intCount] != 0); posmath(sales, &intCount, &total, &stotal); cout << "\n" << endl; printf("Subtotal: %.2lf\n", stotal); printf("GST (5%): %.2lf\n", sales.tftax); printf("PST (8%): %.2lf\n", sales.tptax); printf("Total: %.2lf\n", total); cout << "\n" << endl;}

/* libpos.cpp * Workshop1's Point of Sales library file. * Copyright (C) 2009 Adrien Kwok. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://forums.xisto.com/no_longer_exists/;. * */#include "stdheader.h"#include "pointofsales.h"void posmath (POS& sales, int *intCount, double *total, double *stotal){ int i; for (i = 0; i < (*intCount); i++){ if (sales.taxable[i] == 'y'){ sales.ftax[i] = sales.price[i] * 0.05; sales.ptax[i] = sales.price[i] * 0.08; } else { sales.ftax[i] = 0; sales.ptax[i] = 0; } sales.tftax += sales.ftax[i]; sales.tptax += sales.ptax[i]; *stotal += (sales.quantity[i] * sales.price[i]); *total += (sales.quantity[i] + sales.ftax[i] + sales.ptax[i]); cout << *stotal << endl; cout << *total << endl; }}

Many thanks,
xboxrulz


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.