Confusing Error in the beginning of my c++ code

This is a discussion on Confusing Error in the beginning of my c++ code within the C++ Programming forums, part of the General Programming Boards category; I have completed my code and the only error is something in the beginning of the code because it says ...

  1. #1
    bry
    bry is offline
    Registered User
    Join Date
    May 2013
    Posts
    4

    Question Confusing Error in the beginning of my c++ code

    I have completed my code and the only error is something in the beginning of the code because it says that its at line one. Can someone explain to me why this is happening? Thanks!

    heres my code:

    Code:
    #include <string>#include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    
    
    
    class bookType
    {
    public:
        bookType();
        void setTitle (string);
        string getTitle ();
        bool compareTitle(string);
    
    
        void setAuthor(string="");
        void showAuthors();
        void updateAuthor(string="");
        string *getAuthors ();
    
    
        void setCopies (int);
        void showCopies ();
        void updateCopies(int);
        int getCopies();
    
    
        void setPublisher(string);
        void showPublisher();
        void updatePublisher(string);
        string getPublisher();
    
    
        void setISBN(string);
        void showISBN();
        void updateISBN(string);
        string getISBN();
        bool compareISBN(string);
    
    
        void setPrice(double);
        void showPrice();
        void updatePrice(double);
        double getPrice();
    
    
    private:
        string title;
        string authors [4];
        string publisher;
        string ISBN;
        double price;
        int copies;
        int authorsNo;
    };
    
    
    #include <iostream>
    #include "bookType.h"
    using namespace std;
    
    
    bookType::bookType()
    {
        title="";
        for (int i=0; i<4; i++)
            authors[i];
        publisher="";
        ISBN="";
        price=0;
        copies=0;
        authorsNo=0;
    }
    
    
    void bookType::setTitle(string myTitle)
    {
        title=myTitle;
    }
    
    
    string bookType::getTitle()
    {
        return title;
    }
    bool bookType::compareTitle (string otherTitle)
    {
        return (title.compare(otherTitle)==0);
    }
    
    
    void bookType::setAuthor(string myAuthor)
    {
        authorsNo=authorsNo % 4;
    
    
        if(myAuthor.compare("")==0)
            return;
        else
        {
            authors [authorsNo]=myAuthor;
            authorsNo++;
        }
    }
    
    
    void bookType::showAuthors()
    {
        for (int i=0; i< authorsNo; i++)
            cout<<authors [i]<< ", ";
        cout<<"\r\r";
    }
    
    
    void bookType::updateAuthor(string myAuthor)
    {
        setAuthor(myAuthor);
    }
    
    
    string *bookType::getAuthors()
    {
        return authors;
    }
    
    
    void bookType::setCopies(int myCopies)
    {
        copies=myCopies;
    }
    
    
    void bookType::showCopies()
    {
        cout<<"There are" <<copies<< "copies of this book.";
    }
    
    
    void bookType::updateCopies(int myCopies)
    {
        copies=myCopies;
    }
    
    
    int bookType::getCopies()
    {
        return copies;
    }
    
    
    void bookType::setPublisher(string myPublisher)
    {
        publisher=myPublisher;
    }
    
    
    void bookType:: showPublisher()
    {
        cout<<publisher;
    }
    
    
    void bookType::updatePublisher(string myPublisher)
    {
        publisher=myPublisher;
    }
    
    
    string bookType::getPublisher ()
    {
        return publisher;
    }
    
    
    void bookType::setISBN(string myISBN)
    {
        ISBN=myISBN;
    }
    
    
    void bookType:: showISBN()
    {
        cout<< ISBN;
    }
    
    
    void bookType::updateISBN(string myISBN)
    {
        ISBN=myISBN;
    }
    
    
    string bookType::getISBN()
    {
        return ISBN;
    }
    
    
    bool bookType::compareISBN(string myISBN)
    {
        return(myISBN.compare(ISBN) == 0);
    }
    
    
    void bookType::showPrice()
    {
        cout<< "The price of this book is  "<<price;
    }
    
    
    void bookType::updatePrice( double myPrice)
    {
        price=myPrice;
    }
    
    
    double bookType::getPrice()
    {
        return price;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by bry View Post
    I have completed my code and the only error is something in the beginning of the code because it says that its at line one.
    Compiles fine for me.

    The exact error message would help a lot.

    Kurt

  3. #3
    bry
    bry is offline
    Registered User
    Join Date
    May 2013
    Posts
    4
    Quote Originally Posted by ZuK View Post
    Compiles fine for me.

    The exact error message would help a lot.

    Kurt
    i get these errors:

    "Error 1 error LNK2019: unresolved external symbol "public: void __thiscall bookType::setPrice(double)" (?setPrice@bookType@@QAEXN@Z) referenced in function _main C:\Users\Bob\documents\visual studio 2010\Projects\isbn\isbn\books.obj"

    "Error 2 error LNK1120: 1 unresolved externals C:\Users\Bob\documents\visual studio 2010\Projects\isbn\Debug\isbn.exe 1 1"

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The error tells you that you forgot to implement
    void bookType::setPrice(double);
    Kurt

  5. #5
    bry
    bry is offline
    Registered User
    Join Date
    May 2013
    Posts
    4
    Quote Originally Posted by ZuK View Post
    The error tells you that you forgot to implement
    void bookType::setPrice(double);
    Kurt

    So how do i fix that?

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Implement the method
    e.g
    Code:
    void bookType::setPrice(double p ) {
         price = p;
    }
    Kurt

  7. #7
    bry
    bry is offline
    Registered User
    Join Date
    May 2013
    Posts
    4
    Thank You So Very Much!

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    >>string authors [4];
    I suggest you std::array, if you can. Then, return a const reference to it from GetAuthors.
    Returning a pointer is extremely dangerous since the caller has no idea how large the array is.
    Another way is to use the iterator idom, but it's a little bit more work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Because you also store the number of authors, you should actually use std::vector<std::string> instead of a fixed array ([4] array, std::array<4>). Vectors keep information about the number of elements stored and make element insertion easier.
    I never put signature, but I decided to make an exception.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by bry View Post
    i get these errors:

    "Error 1 error LNK2019: unresolved external symbol "public: void __thiscall bookType::setPrice(double)" (?setPrice@bookType@@QAEXN@Z) referenced in function _main C:\Users\Bob\documents\visual studio 2010\Projects\isbn\isbn\books.obj"

    "Error 2 error LNK1120: 1 unresolved externals C:\Users\Bob\documents\visual studio 2010\Projects\isbn\Debug\isbn.exe 1 1"
    That's a linker error, not a compiler error; as such, there is no line number in this instance.
    Afterall, there is no line number for something that does not exist.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confusing error :S
    By teadrinker in forum C++ Programming
    Replies: 2
    Last Post: 01-28-2008, 10:57 AM
  2. Really confusing error
    By Ganoosh in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2005, 11:07 AM
  3. confusing error - please have a look at my code
    By IceBall in forum Windows Programming
    Replies: 9
    Last Post: 12-21-2003, 12:44 PM
  4. confusing code
    By brutal in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2002, 07:02 AM
  5. confusing error.... plz help
    By heavyd in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2002, 07:44 PM

Tags for this Thread


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