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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
intDigitalTime::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:
intDigitalTime::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
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?
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.
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.
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.
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
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.
Hi all, i got the same problem with programming on eclipse.
But, when i saved project and build it again, it works!!!...)))
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.cdt.doc.user/ta
sks/cdt_t_autosave.htm
resolve for eclipse