Like Tree1Likes
  • 1 Post By Salem

#include

This is a discussion on #include within the C++ Programming forums, part of the General Programming Boards category; I have three files. main.cpp webcounter.cpp webcounter.h I have my class declarations in my webcounter.h file. I have my class ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    13

    #include

    I have three files.

    main.cpp
    webcounter.cpp
    webcounter.h

    I have my class declarations in my webcounter.h file.
    I have my class definitions in my webcounter.cpp file.

    How do I include both files to run in my main.cpp file?

    My professor told us we shouldn't include .cpp files, yet I'm not understanding another way to get both my class definitions and declarations to be understood in the main.cpp file so they can compile correctly.

    If i include the .cpp file into my main.cpp file, it works, but I want to know the correct way of going about this.

    Thank you

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    How are you compiling your program? What compiler/IDE? You should be adding the .cpp file to your project, not including the file.

    Jim

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    13
    I'm not sure I understand. I created the file in vim, and I compiled it in the command prompt using g++ main.cpp

    I have a feeling you're asking a more in depth question than I can answer, I'm new to programming.

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    13
    How would I go about adding a .cpp file to my project? With a makefile?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > I'm not sure I understand. I created the file in vim, and I compiled it in the command prompt using g++ main.cpp
    In which case, the simple answer is

    g++ main.cpp webcounter.cpp

    When you get a few more files, this gets cumbersome, at which point you'll be eager to know about makefiles.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does #include indirectly include the source file too?
    By Lord Asriel in forum C Programming
    Replies: 10
    Last Post: 11-30-2011, 07:20 AM
  2. Replies: 1
    Last Post: 11-06-2011, 05:20 PM
  3. basic difference between #include<> and #include""
    By gunjansethi in forum C Programming
    Replies: 1
    Last Post: 03-26-2010, 12:53 AM
  4. #include <windows.h> and #include <wininet.h>
    By steve1_rm in forum C++ Programming
    Replies: 4
    Last Post: 03-30-2009, 11:14 AM
  5. Which came first? #include <stdio.h> or #include <stdlib.h> ?
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-14-2002, 09:58 PM

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