Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Beginner question using headers

Started 1 month, 3 weeks ago by Jacob Dixon
Hello! I acutally program in C# and chose to start learning C++. I have two questions. One would be if I develop a C++ application using visual c++ 2008, is there a way for it to be converted to run on Mac OS X? Or do you have to write it over in a different IDE? The main question I have is I was trying to learn from this tutorial I found on www.learncpp.com. It seems the tutorials were geared ...
Site: CodeProject: Discussion Boards. Free source code and programming help  CodeProject: Discussion Boards. Free source code and programming help - site profile
Forum: Visual C++ / MFC  Visual C++ / MFC - forum profile
Total authors: 5 authors
Total thread posts: 11 posts
Thread activity: no new posts during last week
Domain info for: codeproject.com

Other posts in this thread:

Jacob Dixon replied 1 month, 3 weeks ago
Nevermind after looking at it again I figured out why. I still have to include int add( int x, int y) { return x + y; } in the HelloWorld.cpp file right? The tutorial didn't show this. IF thats why then whats the point of putting that other code in the header file when you could add int add( int x, int y) at the top of the HelloWorld.cpp file? Or I'm guessing you would...

«_Superman_» replied 1 month, 3 weeks ago
Jacob Dixon wrote: One would be if I develop a C++ application using visual c++ 2008, is there a way for it to be converted to run on Mac OS X? Or do you have to write it over in a different IDE? If you don't use any Microsoft specific functions, you would be able to reuse the code, but you would still need to compile it using a compiler for the MAC. As for you second question, where is ...

«_Superman_» replied 1 month, 3 weeks ago
The whole build process consists of a compilation process and a linking process. Including the header is for the compiler to figure out the signature of the function. The linker needs the actual definition of the function.

Jacob Dixon replied 1 month, 3 weeks ago
Superman, That was it, I never defined it. The tutorial just showed int add( int x, int y) , It never showed the rest. So when I put this in the add.h file: int add( int x, int y) { return x + y; } It worked perfectly. I should of known better Thanks for helping out!

Chris Losinger replied 1 month, 3 weeks ago
in general, you should avoid putting code in a .H file. put this in the .C/.CPP: int add( int x, int y) { return x + y; } and put this in the .H: extern int add( int x, int y); that extern says "there is a function which looks like this, but is implemented somewhere else". that will satisfy the compiler. the linker will take care of the rest. the reason you don't want to ...

Jacob Dixon replied 1 month, 3 weeks ago
Ohhh! Ok I understand. I haven't got far into the tutorials just yet but I figure on down they line they will talk about extern and more of the best practices. Thanks guys

Tim Craig replied 1 month, 3 weeks ago
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function. Or you're doing a naked inline global function. And about the only time that happens (or should IMNSHO) in C++ programs are those places you need those pesky friend functions that there's just no way around.

LunaticFringe replied 1 month, 3 weeks ago
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function. ... or it's a template class. modified on Sunday, November 8, 2009 3:21 PM

Chris Losinger replied 1 month, 3 weeks ago
yep. i was counting that as part of the 'class member function' category.

LunaticFringe replied 1 month, 3 weeks ago
Ah. Very good.

 

Top contributing authors

Name
Posts
Jacob Dixon
4
user's latest post:
Beginner question using headers
Published (2009-11-07 20:41:00)
Ohhh! Ok I understand. I haven't got far into the tutorials just yet but I figure on down they line they will talk about extern and more of the best practices. Thanks guys
«_Superman_»
2
user's latest post:
Beginner question using headers
Published (2009-11-07 16:57:00)
The whole build process consists of a compilation process and a linking process. Including the header is for the compiler to figure out the signature of the function. The linker needs the actual definition of the function.
LunaticFringe
2
user's latest post:
Beginner question using headers
Published (2009-11-08 16:26:00)
Ah. Very good.
Chris Losinger
2
user's latest post:
Beginner question using headers
Published (2009-11-08 16:13:00)
yep. i was counting that as part of the 'class member function' category.
Tim Craig
1
user's latest post:
Beginner question using headers
Published (2009-11-08 03:07:00)
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function. Or you're doing a naked inline global function. And about the only time that happens (or should IMNSHO) in C++ programs are those places you need those pesky friend functions that there's just no way around.

Related threads on "CodeProject: Discussion Boards. Free source code and programming help":

Related threads on other sites:

Thread profile page for "Beginner question using headers" on http://www.codeproject.com. This report page is a snippet summary view from a single thread "Beginner question using headers", located on the Message Board at http://www.codeproject.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity