A member function is a function that belongs to a class or structure. For example, all your Engine functions are member functions of the Engine class. A non-member function is a function that does not belong to a class or structure. A static member function is a function that belongs to a class but is declared with the static keyword.
Code:
/* This is a member function of the Engine class. */
void Engine::Collect()
{
cout<<"Engine Collecting Data "<<ClassName<<endl;
}
/* This is a non-member function. It does not belong to a class.
void Eat()
{
cout << "That was yummy!" << endl;
}
Here is the corrected code. Changed lines have been highlighted and comments are inline.
Code:
// WindowEngine.h
#pragma once
#include <string>
#include "stdafx.h"
#include <Windows.h> // System headers should be surrounded with <> rather than "".
using namespace std;
class Engine
{
public:
Engine::Engine(void);
Engine::Engine(string strClassName);
Engine::~Engine(void);
void Engine::Collect();
protected:
string ClassName;
private:
// This function commented out. We don't need it.
//BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam);
// Declare this function static so it can be used as a callback.
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
};
Code:
// WindowEngine.cpp
#include "WindowEngine.h"
#include <iostream> // Added header for cout, etc.
using namespace std;
Engine::Engine(void)
{
ClassName = "Default";
cout<<"Engine Constructor Default"<<endl;
}
Engine::Engine(string strClassName)
{
ClassName = strClassName;
cout<<"Engine Constructor "<<strClassName<<endl;
EnumWindows(EnumWindowsProc, (LPARAM) this);
}
Engine::~Engine(void)
{
cout<<"Engine Deconstructor "<<ClassName<<endl;
}
void Engine::Collect()
{
cout<<"Engine Collecting Data "<<ClassName<<endl;
}
//This function commented out, not needed...
//BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)
//{
// return false;
//}
BOOL CALLBACK Engine::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
// This is a static member function so can be used as a callback...
// Do something here...
return TRUE;
}