Linking Errors

This is a discussion on Linking Errors within the C++ Programming forums, part of the General Programming Boards category; im getting better at all this stuff. i can fix most of my errors on my own. but im getting ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    45

    Linking Errors

    im getting better at all this stuff. i can fix most of my errors on my own. but im getting linking errors now and i have no clue how to fix them. anybody know whats wrong with this?


    heres my errors im getting:

    Ch09Ex02.obj : error LNK2001: unresolved external symbol "public: void __thiscall NonFiction::showNonFiction(void)" (?showNonFiction@NonFiction@@QAEXXZ)
    Ch09Ex02.obj : error LNK2001: unresolved external symbol "public: void __thiscall Fiction::showFiction(void)" (?showFiction@Fiction@@QAEXXZ)
    Debug/Ch09Ex02.exe : fatal error LNK1120: 2 unresolved externals



    Code:
    #include<iostream.h>
    #include<string.h>
    
    class Book
    {
    	protected:
    		char Title[20];
    		char Author[20];
    	public:
    		void getData(const char title[20], const char author[20]);
    		void showData();
    };
    
    class Fiction:public Book
    {
    	private:
    		int readingLevel;
    	public:
    		void getData(const char title[], const char author[], const int level);
    		void showFiction(void);
    };
    
    class NonFiction:public Book
    {
    	private:
    		int numPages;
    	public:
    		void getData(const char title[], const char author[], const int pages);
    		void showNonFiction(void);
    };
    void Fiction::getData(const char title[], const char author[], const int level)
    {
    	strcpy(Title,title);
    	strcpy(Author, author);
    	readingLevel=level;
    }
    void NonFiction::getData(const char title[], const char author[], const int pages)
    {
    	strcpy(Title, title);
    	strcpy(Author, author);
    	numPages=pages;
    }
    
    void main()
    
    {
    
      Fiction novel;
    
      NonFiction manual;
    
      novel.getData("Scarlet Letter","Hawthorne",10);
    
      manual.getData("Log Cabin Building","Landers",328);
    
      novel.showFiction();
    
      manual.showNonFiction();
    
    
     }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    looks to me like you have forgotten to write 2 functions...

    NonFiction::showNonFiction()
    and
    Fiction::showFiction()

    The compiler can see the decs but not the defs. Not a problem to a compiler but it is to a linker as the linker is trying to find the code for the function calls above and it cant so it chokes.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking errors
    By Zeeshan in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2009, 02:10 AM
  2. unresolved external symbols...linking errors in VC++
    By rammohan2b in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2009, 02:19 AM
  3. HELP!!Why and How to solve this linking errors.
    By huwan in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:30 AM
  4. Replies: 8
    Last Post: 04-27-2006, 11:39 AM
  5. Linking Errors...
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2002, 08:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21