0

So I am trying to figure out how to use c++. The first step is to get a GUI that will work well, so I decided to use eclipse as I have used it frequently with java. However, while it is easy enough to make several files in java that all have the same main class within a folder, I can't figure out how to do it with c++. Note: (I want several main classes because I'm not making a huge program, rather, I plan to create several small programs for competitive programming sites like codeforces.) I've tried to figure out makefiles and .h and .cpp but none of it works for me (likely because I don't really know how to use them).

I don't know what kind of project to create (that is, executable, shared library, static, makefile project) that will best suit my purposes. I've tried lot with what seems to be the default (executable) and what I've heard some people say I should use (makefile) but haven't gotten anything satisfying.

Picture of this menu

When I try to use executable I always get an error saying I can't have multiple main() functions as soon as I add another class, even if I make the main function private in the .h file.

Picture of this error

When I try to use the makefile like I've seen people suggest, well, I don't even know what a makefile is and honestly it doesn't seem to do much, when I delete it nothing changes and I can't even run the other classes, when I try to it just runs the one with the same name as the project, run configurations don't really change anything.

Please help, I've been stuck on this for hours :(

Community
  • 1
  • 1
Alex Li
  • 246
  • 4
  • 11
  • 1
    Get a book. Unlike Java the `main` entry point of a C++ program is a standalone function not a class member function and there can only be one in an exeutable (program). List of books: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Documentation of `main`: http://en.cppreference.com/w/cpp/language/main_function – Richard Critten Jun 22 '17 at 19:00
  • In Eclipse, a project with an executable and Eclipse managed makefiles can only have one and only one main() function and can produce only one executable. You need to make a "makefile" project, in which case you can do whatever you want as long as you know how to write the proper makefiles yourself. Doing so properly is a **huge** topic, more than a simple answer here can teach you. – nos Jun 22 '17 at 19:09

1 Answers1

0

I would suggest finding some good tutorials online and following them to learn a bit more about the language and its ecosystem in general, first. IDEs are great as they make things easier for professionals, but can be overwhelming for someone just starting out.

It's better to learn the raw tools that you would need to build an application, so you can appreciate what the IDE does for you, and why.

Jason Miesionczek
  • 14,268
  • 17
  • 76
  • 108
  • :( Not what I want to hear, but possibly what I need. What kind of raw tools should I use though? I feel like it's hard to learn without being able to type something out – Alex Li Jun 22 '17 at 20:09
  • Nowadays people are using CMake for building C++ projects. Might be a good place to start there. – Jason Miesionczek Jun 22 '17 at 20:31