![]() |
|
#1
|
|||
|
|||
Operator overloading (not happening)This is the second listing where I've had this exact same problem now.
I'm learning C++ from a book (Sams Teach Yourself C++ in 21 days, hmm), and have matched the code letter for letter (I think) but am getting a compile error. CPP / C++ / C Code:
This comes back with - Code:
overloading "=" worked fine. Any help is greatly appreciated as I'm now having to modify code from the book just to get stuff to compile, and its making my brain ache. It's MS Visual C++ v6. |
|
#2
|
|||
|
|||
|
Hmmm, that's tricky. Does it give you an error line number?
Could you attach the entire code if possible? The error is essentially saying rubbish that there is no << operator defined that can output strings. You have included string library? GF |
|
#3
|
|||
|
|||
|
Cheers for the reply. That was including string.h, which I had changed from <string> in an attempt to get this working - which I'll guess was daft, anyway.
including <string> gets this error..... maybe a bit long for posting I dont know but.....full listing with <string> - CPP / C++ / C Code:
Compiling... vectors.cpp Linking... LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/vectors.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. vectors.exe - 2 error(s), 0 warning(s) gone over this a thousand times...but got it working fine without the << operator bit, changing show_vector to access member functions in turn. |
|
#4
|
|||
|
|||
|
where'd those faces come from? wasnt me.
|
|
#5
|
||||
|
||||
|
Those 'faces' otherwise known as 'smilies', are automatically translated by the forum script when it detects e.g. :) in your post.
You can disable this 'translation', especially when you're pasting code in your posts by checking the little box Disable Smilies in This Post under Options: and below the main box (where you usually type your message/post to this board). By the way, you can wrap your C++ code posting your code like this: Code:
This will result in syntax highlighted code (my work on getting the syntax highlighting working well for C++ is as yet incomplete, so bear with me for a while), see your edited post above for the after-effects using these bbcode tags. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#6
|
|||
|
|||
|
It's a peculiar error. I notice that the overloaded function isn't declared anywhere.
You could try inserting the following into the class definition (under public): CPP / C++ / C Code:
This could add validity to the function, explicitly allowing it access to the class's components. I've done a few searches for errata for this book, hope some of these might clean up some typos: www.libertyassociates.com - from the authors mouth www.computersciencelab.com - if you're trying GCC GF |
|
#7
|
|||
|
|||
|
thats something i tried actually, and again i get a new but equally annoying error.........
D:\Program Files\Microsoft Visual Studio\MyProjects\vectors\vectors.cpp(92) : error C2593: 'operator <<' is ambiguous D:\Program Files\Microsoft Visual Studio\MyProjects\vectors\vectors.cpp(111) : see reference to function template instantiation 'void __cdecl show_vector(const class std::vector<class student,class std::allocator<class student> > &)' being c ompiled Error executing cl.exe. does the fact that i had the same problem with an earlier listing, again copying code letter for letter, mean anything to anybody. are there buggy releases of the compiler or anything? |
|
#8
|
|||
|
|||
|
cheers for the links.
i dropped the source code from the book directly into a new project - and it worked. copied the operator<< function directly into my code (changing back the function names), and i get - LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/vectors.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. again. must be a typo somewhere on my part but i'm damned if i can find it, even scanned the white space in the window for rogue characters. and whats stopping the compiler flagging a specific line in the code? i'll wait for the next listing that uses this and see what happens. |
|
#9
|
|||
|
|||
|
I've done a little Googling, and most of the time when this error comes up, there's a library file that is not in the right place. Make sure that these library files are in the correct directories too, if they're missing bad things will happen.
Otherwise, I'm stuck! GF |
|
#10
|
|||
|
|||
|
Quote:
It looks to me like you are creating a Win32 application instead of a Win32 console application. It doesn't appear that there is a problem with your code, it's during the link phase that it is breaking. |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help not sure wat is happening | saxon | Computer Software Forum - Windows | 2 | 26-Mar-2006 17:37 |
| What's happening to nature? | priyanka | Open Discussion Forum | 7 | 30-Oct-2004 13:58 |
| Looking like a Google 'DeepCrawl'? | JdS | Search Engine Optimization Forum | 13 | 27-Dec-2003 02:41 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The