473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Link error.

Roonie
99
so i signed up this morning and posted an introduction. i mentioned an error that was and then was no longer . . . thus it ceased to be a problem . . .

but i guess i spoke too soon.

anyways, i have not been programming for a while (six years) and this is the first time i am using a container class . . . i wrote a very simple program to test out the vector container:

main.cpp:
----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. #include "fish.cpp"
  6.  
  7. using namespace std;
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     typedef std::vector<Fish> t_FishVect;
  12.     t_FishVect school(10);
  13.  
  14.     for(int i = 0; i < 10; i++)
  15.     {
  16.             school[i].setFace(i);
  17.     }
  18.  
  19.     for(int i = 0; i < 10; i++)
  20.     {
  21.             cout << school[i].getFace();
  22.     }
  23.  
  24.     cout << "\n";
  25.     system("PAUSE");
  26.     return EXIT_SUCCESS;
  27. }
----------------------------------------------------------------------------

fish.cpp:
----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. class Fish
  2. {
  3.       public:
  4.              Fish() {face = 0;}
  5.              Fish(int fishFace) {face = fishFace;}
  6.              ~Fish();
  7.  
  8.              void setFace(int newFace) {face = newFace;}
  9.              int getFace() {return face;}
  10.  
  11.       private:
  12.               int face;
  13. };
----------------------------------------------------------------------------

everything compiles, but the linker exits with errors:

[Linker error] undefined reference to 'Fish::~Fish()' (x3)

now when i create a container of pointers to Fish it works. but as i understand it, the whole point of containers is to get away from pointers and other such nasties, so i consider a container of pointers to be a failure at an attempt to ease the use of pointers.

as i said, ive never used a container before and im a bit rusty on c++ in general (having not used it for 6 years) so if im missing something simple, please let me know . . . earlier i cut out, saved and then pasted back the exact same portion of code (the Fish class declaration) and it worked. ill try that again, but id rather find a solution that didnt involve my linker being in a good or bad mood.

maybe i just need a different one. i would rather not do that though . . . im using the dev-cpp ide which uses gcc and i like open source.

any help would be greatly appreciated.
Mar 18 '07 #1
10 1378
horace1
1,510 Expert 1GB
in Fish you declare the destructor
Expand|Select|Wrap|Line Numbers
  1.              ~Fish();
  2.  
but don't define it (give it any code enclosed in {}), try
Expand|Select|Wrap|Line Numbers
  1.              ~Fish() {};
  2.  
Mar 18 '07 #2
Roonie
99
trying . . .

. . . same errors. i dunno. i think ill use a different compiler just to see . . .

(also, thx for the code tags . . . didnt see that on first glance . . .)
Mar 18 '07 #3
arne
315 Expert 100+
trying . . .

. . . same errors. i dunno. i think ill use a different compiler just to see . . .

(also, thx for the code tags . . . didnt see that on first glance . . .)
Compiles fine for me with horace1's correction.
Without it, I see the undefined reference errors you mentioned.
Mar 18 '07 #4
Roonie
99
what compiler are you using arne?

also, when i changed the Fish function declarations to the more appropriate style for larger functions (with prototypes and then Fish::_____'s) . . . i got additional link errors complaining that each function was defined more than once.

im beginning to think that i just need a different compiler.
Mar 18 '07 #5
horace1
1,510 Expert 1GB
I have compiled and run your code with the GNU g++ compiler and Borland CBuilder without problems (after I fixed the destructor). A run gives
0123456789
Press any key to continue . . .

post your updated code?
Mar 18 '07 #6
Roonie
99
that is exactly what im trying to get . . .

main.cpp is the same.

fish.cpp:
Expand|Select|Wrap|Line Numbers
  1. class Fish
  2. {
  3.       public:
  4.              Fish();
  5.              Fish(int fishFace);
  6.              ~Fish() {};
  7.  
  8.              void setFace(int newFace);
  9.              int getFace();
  10.  
  11.       private:
  12.               int face;
  13. };
  14.  
  15. Fish::Fish()
  16. {
  17.      face = 0;
  18. }
  19.  
  20. Fish::Fish(int fishNum)
  21. {
  22.      face = fishNum;
  23. }
  24.  
  25. void Fish::setFace(int newFace)
  26. {
  27.      face = newFace;
  28. }
  29.  
  30. int Fish::getFace()
  31. {
  32.      return face;
  33. }
  34.  
Mar 18 '07 #7
arne
315 Expert 100+
what compiler are you using arne?
I am using gcc 4.0.2.
Mar 18 '07 #8
arne
315 Expert 100+
A run gives
0123456789
Equivalent result for me:
0123456789
sh: PAUSE: command not found
Mar 18 '07 #9
horace1
1,510 Expert 1GB
that is exactly what im trying to get . . .

main.cpp is the same.

fish.cpp:
Expand|Select|Wrap|Line Numbers
  1. class Fish
  2. {
  3.       public:
  4.              Fish();
  5.              Fish(int fishFace);
  6.              ~Fish() {};
  7.  
  8.              void setFace(int newFace);
  9.              int getFace();
  10.  
  11.       private:
  12.               int face;
  13. };
  14.  
  15. Fish::Fish()
  16. {
  17.      face = 0;
  18. }
  19.  
  20. Fish::Fish(int fishNum)
  21. {
  22.      face = fishNum;
  23. }
  24.  
  25. void Fish::setFace(int newFace)
  26. {
  27.      face = newFace;
  28. }
  29.  
  30. int Fish::getFace()
  31. {
  32.      return face;
  33. }
  34.  
this compiles and runs with the original main() OK using g++
Mar 18 '07 #10
Roonie
99
alright . . . i cant seem to figure this out with the time i have right now. (my drunkie sister is going camping tonight and needs me to make a run for her).

thanks for the help guys . . . i guess my plan at the moment is to take a breather for a while and then try just straight up the newest release of gcc.

and if that fails, ill try a different container class.

thanks again.
Mar 18 '07 #11

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

Similar topics

6
by: Matthew Houseman | last post by:
All, I've created a synonym that points to a package over a database link like so: CREATE SYNONYM API_MYLINK FOR USER.CSAPI_V2@INSTANCE.DOMAIN.COM I've granted execute like so: grant execute...
1
by: Andrew V. Romero | last post by:
I have a script that I am working on for an intranet tool and in this script I have a form, which when submitted the onSubmit command calls calculate(). In this calculate function, I have it do...
10
by: Gary Hughes | last post by:
I'm getting the following error when attempting to link a managed C++ dll. I can't find any reference to these errors with google. Can anyone help? I've included the class definition causing the...
10
by: Ian Lazarus | last post by:
Hello. How do "unresolved token" link errors occur. How do I fix them? Linking... LINK : error LNK2020: unresolved token (0A000015) ??_7type_info@@6B@ LINK : error LNK2020: unresolved token...
4
by: Jun | last post by:
anyone know how this error shows? how can i solve this? LINK : error LNK2020: unresolved token (0A0000EA) _AtlBaseModule LINK : error LNK2020: unresolved token (0A0000EC) atlTraceGeneral LINK :...
13
by: rdemyan via AccessMonster.com | last post by:
My front-end code manually links to the backend file. I was wondering what stops Access from linking to the system tables in the backend file. Is it just by virtue that they are hidden? This...
5
by: Bruce | last post by:
I am getting a lot of link errors when compiling in the debug build but not release. I am compiling a CLR managed code class library. I believe the link errors are actually being caused by a...
10
richardhodge
by: richardhodge | last post by:
I am a VB6 database programmer and have run into a small problem. The company I work for primarily uses Microsoft Access 2000 for the database that is the back end for our software. Well the...
7
by: ApexData | last post by:
Hello I currently Link the FE/BE using the LinkTables Option and the Linked Table Manager. Any time I need to move the BE to another location, I have to go through this process over again. I...
3
by: Kevin | last post by:
Hi guys, I am a beginner for QT, and I installed the free qt 2.3 under windows (XP), as well as the MS's free VC expression edition (for their compilers, linkers, etc), and the SDK tool. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.