Including extra .cpp files visual2008

This is a discussion on Including extra .cpp files visual2008 within the C++ Programming forums, part of the General Programming Boards category; Hi how do you go about including two or more .cpp files in visual express 2008?Have no problem including headers ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    38

    Including extra .cpp files visual2008

    Hi how do you go about including two or more .cpp files in visual express 2008?Have no problem including headers but cant seem to fathom including extra .cpp files.Tried to find it on msdn but just ended up going around in circles....

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,313
    Why do you need to include .cpp files? The one special case I can think of when you would include a source file is to include it in a header file where templates are defined.
    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
    Sep 2004
    Location
    California
    Posts
    3,246
    I think he is asking how to add new .cpp files to a project in the IDE. I've never used VS 2008, but can't you just add a generic file and name it with a .cpp extension?

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    38
    Yeah sorry didnt make myself clear.

    At the moment I have

    main.cpp
    main.h(function prototype's)
    playerClass.h(my structs and class's)

    and I want to include a playerClass.cpp with the structs and classes are initialised.I have being doing that in main.cpp but it is starting to get unwieldy.

    I have added an extra .cpp file in the manager project(as a source file) but when I go to compile it gives errors that the varibles are un-declared

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by Cathalo View Post
    I have added an extra .cpp file in the manager project(as a source file) but when I go to compile it gives errors that the varibles are un-declared
    Sounds like everything is working. Go fix your bugs.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    38
    Quote Originally Posted by brewbuck View Post
    Sounds like everything is working. Go fix your bugs.

    i Have for example int x=10 in playerClass.cpp.If i cout<<x; in main I get the error undeclared var.Main isnt picking up playerClass.cpp at all.

    Will keep at it.Doesnt help that Im off cigarettes 5 days.Nearly hopped the pc off the wall.twice

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Cathalo View Post
    i Have for example int x=10 in playerClass.cpp.If i cout<<x; in main I get the error undeclared var.Main isnt picking up playerClass.cpp at all.

    Will keep at it.Doesnt help that Im off cigarettes 5 days.Nearly hopped the pc off the wall.twice
    That's the way it's supposed to work. Variables aren't related between functions, let alone between files.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    38
    So what can go in the .cpp file then?

    Will just keep using one cpp file and the headers.Not worth the head ache.And its not as If im programming Microsoft Office suite 2009 or half life 3

    Thanks to all

  9. #9
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    If you're use to other compilers like codeblocks or devcpp where you can include a header file with the prototypes AND the functions then yea visual studio 2008 can be confusing. I know it was for me at first.

    For my projects I use .cpp files for the function 'code' and the .h header files for prototyping the functions. That way VS doesn't complain about having undefined variables/functions. Just include the header file in the main.cpp. So basically in the end you should have;

    -main.cpp
    -main.h
    -playerClass.cpp // all the functions
    -playerClass.h //all the function prototypes

  10. #10
    Registered User
    Join Date
    Feb 2009
    Posts
    38
    Got ye.I think i was trying the impossible

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to better manage large .cpp files
    By 39ster in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2008, 08:24 AM
  2. Using multiple .cpp files for programs
    By DevEight in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2007, 07:56 AM
  3. Class files (.h and .cpp
    By Todd in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 02:07 PM
  4. How do I include .cpp files in my main?
    By MadForIt in forum C++ Programming
    Replies: 8
    Last Post: 02-11-2002, 06:40 PM
  5. Including Files
    By Kinc in forum C++ Programming
    Replies: 1
    Last Post: 01-02-2002, 02:31 PM

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