Menu

problem with #include for header file

2010-02-28
2012-09-26
  • Ian Engelbrecht

    Ian Engelbrecht - 2010-02-28

    Hi,

    I get an error when compiling separate header (.h) and implementation (.cpp)
    files. Header file is dtime.h. This is a very basic programming example for a
    starter course I'm doing. Log is as follows:
    {
    Executing g++.exe...
    g++.exe "E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.cpp" -o
    "E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.exe"
    -L"C:\UNISA\mingw\lib" -L"E:\CurrentProjects\UNISAStudies\2010\C++Projects"
    E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.cpp:4:10: #include
    expects "FILENAME" or <FILENAME>
    E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.h: In function
    std::ostream& operator<<(std::ostream&, const DigitalTime&)': E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.h:42: error:int
    DigitalTime::hour' is private
    E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.cpp:71: error: within
    this context
    E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.h:43: error: int DigitalTime::minute' is private E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.cpp:72: error: within this context E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.h:43: error:int
    DigitalTime::minute' is private
    E:\CurrentProjects\UNISAStudies\2010\C++Projects\dtime.cpp:74: error: within
    this context

    Execution terminated
    }
    I've tried full path for dtime.h in dtime.cpp, but still gives this error.

    Thanks

    Ian

     
  • Ian Engelbrecht

    Ian Engelbrecht - 2010-02-28

    Sorry, to clarify, the problem is the "#include expects "FILENAME" or
    <FILENAME>". What do I need to do so that the compiler can find and use the
    header file correctly?

     
  • cpns

    cpns - 2010-02-28

    I imagine the error message means exactly what it says, but without seeing
    line 4 of dtime.cpp how can we tell!?

    It is simply telling you that the file parameter of #include must be enclosed
    on " " or < >; which you must not have done.

     
  • Ian Engelbrecht

    Ian Engelbrecht - 2010-03-01

    Here is line 4 of dtime.cpp:

    include "dtime.h"

    The " " were included, as per instructions for including programmer created
    header files. So the problem must be something else.

     
  • cpns

    cpns - 2010-03-01

    Post everything that precedes line 4, and if the preceding line is itself a

    include, you may need to look at the content of that file. Since the log

    clearly indicates that dtime.h was included (because it has errors), it must
    be complaining about an earlier line.

     
  • Ian Engelbrecht

    Ian Engelbrecht - 2010-03-07

    Found and error in the one of the previous #include directives, which appears
    to have been causing the problem. Apologies for time wasting on a very basic
    error

     
  • cpns

    cpns - 2010-03-07

    Found and error in the one of the previous #include directives

    So you mean "Thanks Clifford, you were right"? You're welcome, no problem. ;-)

    It was an entirely legitimate question, but you'd have saved a lot of time if
    you'd have followed the guidelines for posting
    here, and posted the code.

     
  • Semuale Fisher

    Semuale Fisher - 2011-06-04

    Hi all, i got the same problem with programming on eclipse.

    But, when i saved project and build it again, it works!!!...)))

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.