yes, I am new to C++. so I got a ask. When including system headers into a cpp file rule of thumb.
if another cpp file is using a system header, why am I getting errors when I use a function call within a different file that does not have the same header files include into that file as well?
this does not happen with C.
point in case.
I have an options.cpp for the use of getopts. when that is completed. it has nothing to do with open display, and load images.
the order of execution,
main.cpp // to do what main does.
options.cpp // to get the options off the cli
files.cpp // to get the file names to load
img.cpp // to load and set the images
(done so far, just need one more set of files( i think), but that is a mute point)
the point is, the only file that needs the system headers for display is main to open display, and img to do the rest, including lmlib2 stuff.
but if I do not have the headers included in the other files between main.cpp and img.cpp I get errors.
that is from commenting out the headers in options.cpp.Code:[Running] cd "/media/data/projects/VSC/C++/mh5000/" && g++ -std=gnu++11 -lX11 -Wall -Wno-switch-enum -Wno-switch `imlib2-config --cflags` `imlib2-config --libs` -Wextra -pedantic -g *.cpp In file included from options.cpp:14:0: img.h:8:1: error: 'Display' does not name a type Display *display; ^~~~~~~ img.h:9:1: error: 'Visual' does not name a type Visual *vis;
if I un-comment them and put them back in then everything works as it should. compile to load and set image on desktop, no errors.
now that I have gotten that far. I thought I'd ask because that seems quirky to have to have every header file included in every file no matter what else errors occur.
these are the header files. I didn't do one at a time, but if I remove them by doing a block comment to hide them that is when those errors show up.
damng it, I need to reset my brain I think.Code:#include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> #include </usr/include/Imlib2.h>