C++ error LNK2019: unresolved external symbol _main referenced in function _tmainCRTStartup -
i complete beginner c++. trying debug code because sure there pointer errors , such still trying understand can't compile it. code java program wrote song class compare methods , have transcribed c++ try , learn differences between languages, code showing no errors can't compile without error popping up. have tried looking @ solutions error have found nothing works here code win32 console project. thank help.
// consoleapplication4.cpp : defines entry point console application. // #include "stdafx.h" #include <string> #include <iostream> using namespace std; class song { private: string artist; string title; string lyrics; public: static int sortcount; static int searchcount; song(string a_artist, string t_title, string l_lyrics) { artist = a_artist; title = t_title; lyrics = l_lyrics; } //compares artist of 1 song another. class artistcomparator { public: int compare(song *o1, song *o2) { string artist1 = (*o1).artist; string artist2 = (*o2).artist; searchcount++; if (artist1.compare(artist2) == 0){ return 0; } searchcount++; return (*o1).artist.compare((*o2).artist); } }; //compares title of 1 song another. class titlecomparator { public: int compare(song arg0, song arg1) { string title1 = arg0.title; string title2 = arg1.title; return title1.compare(title2); } }; public: //testing method make sure song class works , //the compareto method works. int main(int argc, char** argv){ song test1 = song("cat", "bat", "this not real song"); song test2 = song("cat", "apple", "also not real song"); int compareresult = test1.compareto(test2); if (compareresult == -1){ std::cout << "test1 comes first"; } else{ cout << "test2 comes first"; cout << test2.tostring(); } }; string getartist(){ return artist; }; string gettitle(){ return title; }; string getlyrics(){ return lyrics; }; string tostring(){ return artist + ", " + title + ", " + lyrics; }; //compareto method used sorting songs. //increments sortcount each time called keep track //of efficiency of sort algorithm. private: int compareto(song other){ sortcount++; int art = artist.compare(other.artist); if (art == 0){ return title.compare(other.title); } else return art; } };
#include "stdafx.h" #include <string> #include <iostream> using namespace std; class song { private: string artist; string title; string lyrics; public: int sortcount; static int searchcount; song(string a_artist, string t_title, string l_lyrics) { artist = a_artist; title = t_title; lyrics = l_lyrics; } //compares artist of 1 song another. class artistcomparator { public: int compare(song *o1, song *o2) { string artist1 = (*o1).artist; string artist2 = (*o2).artist; searchcount++; if (artist1.compare(artist2) == 0){ return 0; } searchcount++; return (*o1).artist.compare((*o2).artist); } }; //compares title of 1 song another. class titlecomparator { public: int compare(song arg0, song arg1) { string title1 = arg0.title; string title2 = arg1.title; return title1.compare(title2); } }; public: //testing method make sure song class works , //the compareto method works. string getartist(){ return artist; }; string gettitle(){ return title; }; string getlyrics(){ return lyrics; }; string tostring(){ return artist + ", " + title + ", " + lyrics; }; //compareto method used sorting songs. //increments sortcount each time called keep track //of efficiency of sort algorithm. int compareto(song other){ sortcount++; int art = artist.compare(other.artist); if (art == 0){ return title.compare(other.title); } else return art; } }; int main(int argc, char** argv){ song test1 = song("cat", "bat", "this not real song"); song test2 = song("cat", "apple", "also not real song"); int compareresult = test1.compareto(test2); if (compareresult == -1){ std::cout << "test1 comes first"; } else{ cout << "test2 comes first"; cout << test2.tostring(); } getchar(); return 0; }
changes done:
- moved
main()
outside class - made
compareto()
functionpublic
being directly called - removed
static
int sortcount
, not update variable without that.
Comments
Post a Comment