Adding items to a list
-
Well, my first comment is: fix your "include guards":http://en.wikipedia.org/wiki/Include_guard
-
Yes! Let me explain. In C (and C++) an #include directive will include the file regardless of whether it has been included before. You can litterally compare this to copy'n'past-ing the header file into the source code whenever there is an #include directive. The include guards are used to make sure every header file is only included once. E.g. if your header file would usually be
@
class Dummy
{};
@
you'd have to use
@
#ifndef DUMMY_H //i.e. if dummy.h has never been included before
#define DUMMY_H //remember that it has been includedclass Dummy
{};#endif //endif after all statements
@
In your case the include guards have to enclose all of your statements (the header files not necessarily because they have their own include guards, but it's usually best to have the include guards be the first and last satements in your header files) -
Ok so if I understand you it should be:
@
#include <windows.h>
#include <list>
#include <QString>#ifndef PROC_H
#define PROC_Hclass ProcInfo
{
public:
HANDLE Proc;
DWORD Base;
int ID;
operator QString() const
{
return QString::number(ID);
}
};std::list<ProcInfo> procList;
bool createProcessList();
DWORD GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId);#endif // PROC_H@
But I still get the same error.
-
Guys. It's not a "try and guess" process. He defined a global variable inside a header. As soon as that header gets included in two or more translation units, the compiler will output multiple definitions of the same name. And the linker will complain. Put that definition in ONE translation unit and you'll be ok.
-
I have another question about this.
The function currently working is:
@
class ProcInfo
{
public:
HANDLE Proc;
DWORD Base;
std::string WindowName;
int ID;
inline operator QString() const
{
return QString::number(ID);
}
};
@How would I mane the QString method return the following format:
"(" + ID + ") " + WindowName
So the output would end up something like:
(432) NotePad
-
@
return QString('(') + QString::number(ID) + ')' + WindowName.c_str()
@
Also have a look at "More Efficient String Construction":http://doc.qt.nokia.com/latest/qstring.html#more-efficient-string-construction