Multiple File Problems

This is a discussion on Multiple File Problems within the C++ Programming forums, part of the General Programming Boards category; I'm trying to see how having several header and .cpp files work. But I'm encountering a problem: "In file included ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    66

    Multiple File Problems

    I'm trying to see how having several header and .cpp files work. But I'm encountering a problem: "In file included from print.cpp"

    It's a very short project, but since there's multiple files, I zipped it up. Thx for the help ppl!
    Attached Files Attached Files
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You haven't referenced any namespaces.
    You haven't #include <iostream> in main.cpp

    This:
    printthis(YES!)
    should be:
    printthis("YES!")

    .. and printthis() returns void, so you can't use it in the middle of a cout statement. Split it up like so:
    Code:
    cout << "Try printthis(): ";
    printthis("YES!");
    cout << "Try printthat(): ";
    printthat("YES!");
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Okay...those were stupid errors, and i just fixed them. However, the same errors are still there. The first one is (and probably da most important one):

    print.cpp line 3 in file included from print.cpp
    Attached Files Attached Files
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You still haven't referenced any namespaces:
    Code:
    #ifndef PRINT_H
    #define PRINT_H
    
    #include <string>
    
    void print(const std::string& s);
    
    #endif
    My guess is you've forgotten that elsewhere as well
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    I didn't want to use any namespaces, and then realize that I have to put std:: infront of string and otherstuff as well....><
    All of the old problems are fixed now, but there's 2 new ones "linker problems: print(const std::string& s) undefined"
    Attached Files Attached Files
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You function implementation for print() is wrong:

    void print(const std::string s)

    You forgot the &
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Thx, I got it now.
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  4. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

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