Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Converting C to C++
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="fakeprogress, post: 2560787"] How would I go about converting this C code to C++? /* LIBRARY is an array of structures */ /* This function compares 'tcode' with */ /* existing codes in the array. */ /* It returns the index of the code in */ /* the LIBRARY structure if it is found. */ int findcode( LIBRARY *b, int n, char *tcode ) { int i; for( i = 0; i < n; i++ ) if( strcmp( b[i].code, tcode ) == 0 ) return i; return -1; } This is what I have: (I just need to know if the code exists [ie, function returns 1] in the class. Indeces are not necessary.) class Book { private: std::string author; std::string title; std::string code; int ncopies; int onloan; public: Book( const std::string &auth, const std::string &tit, const std::string &cd, int ncop, int nonloan ); Book( const std::string &auth, const std::string &tit, const std::string &cd, int ncop ); const std::string &getAuthor( ) const; const std::string &getTitle( ) const; const std::string &getCode( ) const; int getNcopies( ) const; int getOnLoan( ) const; void Borrow( int qty ); void nReturn( int qty ); }; typedef std::vector<Book> Library; int findcode( Library &lib, std::string tcode ) { for( Library::iterator itor = lib.begin( ); itor != lib.end( ); ++itor ) { Book &b = *itor; if( ( tcode.compare( b.getCode ) ) == 0 ) return 1; } return -1; } However, I get this error: 37 C:\CIS\22\asn2\asn2.cpp no matching function for call to Something about the use of compare() in the C++ findcode()... Help, please?[/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Converting C to C++
Top