Re: Cyclic reference? (full)
There are number of different ways to do what you want.
Before I start let me mention that I don't know what type
m_MonitorFileCreation is, but I assume it is CMyDirHandler. (I think you
meant m_DirChangeHandler, but type m_MonitorFileCreation).
You can use forward declaration to define CMyDirHandler in your
CMonitorFileCreation header, but that will force you to change
m_DirChangeHandler to a pointer.
The other method is to create an intermediate class that
CMonitorFileCreation inherits from. That class can declare a pure virtual
method for On_FileCreated, that CMonitorFileCreation actually will define.
That way you won't end up with a circular include.
AliR.
"Jeova Almeida" <jeovaalmeida@yahoo.com> wrote in message
news:%23l38$PlSJHA.5812@TK2MSFTNGP05.phx.gbl...
Hello,
(please ignore the previous post, I made a mistake and sent it before I
had finished writing it)
I've got an excellent code from www.codeproject.com by Wes Jones to
receive
notifications when a file is created or modified in a particular folder.
It's based on two main classes:
CDirectoryChangeWatcher - to detect file creation and modification events
CDirectoryChangeHandler - a class that receives notification about file
changes from CDirectoryChangeWatcher, which should be inherited so you can
handle the notifications on your app.
I'm developing a simple app which detects when a specific type of file is
created and create a hash (md5) for it. I created a class called
CMonitorFileCreation which uses both classes from Wes Jones, and has two
member functions:
- CDirectoryChangeWatcher m_DirWatcher;
- CMyDirectoryChangeHandler m_DirChangeHandler;
The watching is started form a method called StartMonitoring() which uses
both member functions above.
The class CMonitorFileCreation is responsible for handling files creation
applying some transformation into it, besides the hash creation, so I want
the
CMyDirectoryChangeHandler (inherited class) to call a member function from
CMonitorFileCreation (On_FileCreated), where the transformation will take
place.
// MyDirhandler.h - please note it includes MonitorFileCreation.h
#pragma once
#include "MonitorFileCreation.h"
#include "DirectoryChanges.h"
class CMyDirHandler : public CDirectoryChangeHandler
{
public:
CMyDirHandler::CMyDirHandler(CMonitorBankSttmFileCreation monitor)
: m_MonitorBankSttmFileCreation(monitor)
{}
// MonitorFileCreation.h - please note it includes MyDirHandler.h
#pragma once
//#include "DirectoryChanges.h"
#include "MyDirHandler.h"
class CMonitorFileCreation
{
public:
// construtor/destrutor
CMonitorFileCreation(void);
virtual ~CMonitorFileCreation(void);
protected:
CDirectoryChangeWatcher m_DirWatcher;
CMyDirHandler m_DirChangeHandler;
public:
void StartMonitoring(void);
protected:
void On_FileCreated(CString strFileName);
};
The above code is not a full version, just enough to state my problem,
some things may be missing.
-----------
When I compile the app, I get
error C2146: syntax error : missing ';' before identifier
'm_MonitorFileCreation'
I think it's because there's a cyclic reference.
How can I achieve what I need? That is, from the CMyDirHandler, call a
method from a method of a CMonitorFileCreation object, considering the
dependencies above.