Newb Question

This is a discussion on Newb Question within the C++ Programming forums, part of the General Programming Boards category; I've just started programming in C++, err at least learning how. I've programmed in VB6 and VB .Net for a ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    8

    Question Newb Question

    I've just started programming in C++, err at least learning how. I've programmed in VB6 and VB.Net for a long time, I just decided I should learn a new language.

    Anyway, I went over to Microsofts' site and got Visual C++ 2008 Express Edition as a compiler. I've created an empty project which right now just contains Main.cpp and Libraries.h, but it won't compile. It keeps telling me the exe of the project cant be found, even though it builds successfully. Am I missing something as a c++ newb or what?

    Here's the code, in case it matters. It does nothing at the moment, but I'm still confused as to why it wont compile and run.

    Main.cpp
    Code:
    #include "Libraries.h"
    
    void Main()
    {
    	return 0;
    }
    Libraries.h
    Code:
    /* LIBRARIES HEADER FILE
    
    	Used to refer parts of the project
    	to some of the more commonly used
    	libraries. */
    
    #include <iostream>
    using namespace std;

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    void Main should be int main

    By the way, do not use using directives like using namespace std; in header files, except within a restricted scope. It is harmless in your example, but you might as well adopt good habits now.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    Ok, I change void Main to int Main like you said, and I took the standard namespace out of the library header file and put it into main, under #include "Libraries.h", and it still wont build :/

    It failed when it was linking, with this error
    'LINK : fatal error LNK1561: entry point must be defined'

    Being a newb to C++ I have no idea what linking is, or how to fix that error. :/ I saw in one of the tips and tricks thing that some compilers won't compile some code for some reason, but I figure when it's this basic it has to be an error somewhere on my part.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    The "entry point" thing refers to the global main function. What you have is a global Main function, which in C++ is not the same as the global main function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    Ohh. I forget how picky C++ is with capitalization xD
    thanks a ton! :]

    One last question, just for clearification.
    Using my library header file to include different things [ie. #include <iostream>] and then referancing my .cpp files to Libraries.h is ok, but putting things like 'using namespace std;' is a no-go, correct?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    Quote Originally Posted by fthmdg
    Using my library header file to include different things [ie. #include <iostream>] and then referancing my .cpp files to Libraries.h is ok, but putting things like 'using namespace std;' is a no-go, correct?
    Pretty much yes. You can find out more about them later.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    They're both "ok" in that they're both legal, but neither is good style, as I understand the term. There's not any point in making a header file of just #include statements; and there's not really any point in trying to make one Libraries.h file that every one of your program uses -- not every program needs <cmath>, and not every program requires <string>, and not every program requires <vector>, so making every program include some large set of include files that it doesn't need is wasteful.

    (EDIT: Obviously if you have your own common functions, putting that in a .h file is perfectly normal. But really, <iostream> is probably the only header that I would expect to find every time in a program.)
    Last edited by tabstop; 04-08-2010 at 11:13 AM.

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    Well there are, more-so will be, more custom functions that the majority of my program will use, so the library header is just for those.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  3. newb question: probs with this program
    By ajguerrero in forum C Programming
    Replies: 5
    Last Post: 04-19-2006, 08:04 AM
  4. newb question
    By Jan79 in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2003, 09:59 AM
  5. Win app, newb question
    By Blender in forum Windows Programming
    Replies: 9
    Last Post: 02-04-2003, 11:17 AM

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