Hello there,
i am forced to use a static function, unfortunately this means i cant call the variables which belong to this class from this function, what si the best way i can overcome this? The variable is gcroot<FileSystemWatcher^ > watcher;
br
Hello there,
i am forced to use a static function, unfortunately this means i cant call the variables which belong to this class from this function, what si the best way i can overcome this? The variable is gcroot<FileSystemWatcher^ > watcher;
br
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
The best way is to make that variable static too. Really, trying to get a non-static member variable form a static function makes no sense at all. What value would you expect: of what instance of the object? Or is there only one instance? In that case, you might want to consider a singleton class, though I doubt if that's the best solution.
All in all, I think this question can't be answered as you went wrong somewhere earlier.
hi guys, here is what i have done so far:
i am using the filesystemwatcher function, the callback functions (or event handlers are static as so:
static void OnChanged(Object* /*source*/, FileSystemEventArgs* e)
{
// Specify what is done when a file is changed, created, or deleted.
Console::WriteLine(S"File: {0} {1}", e->FullPath, __box(e->ChangeType));
}
static void OnRenamed(Object* /*source*/, RenamedEventArgs* e)
{
// Specify what is done when a file is renamed.
Console::WriteLine(S"File: {0} renamed to {1}", e->OldFullPath, e->FullPath);
}
Now in the same class but in a different function i have initialised the fileSystemWatcher as so:
FileSystemWatcher* watcher = new FileSystemWatcher();
watcher->NotifyFilter = static_cast<NotifyFilters>( NotifyFilters::LastAccess | NotifyFilters::LastWrite
| NotifyFilters::FileName | NotifyFilters:irectoryName );
watcher->Filter = "myfile.txt";
// Add event handlers.
watcher->Changed += new FileSystemEventHandler(0, Watcher::OnChanged);
watcher->Created += new FileSystemEventHandler(0, Watcher::OnChanged);
watcher->Deleted += new FileSystemEventHandler(0, Watcher::OnChanged);
watcher->Renamed += new RenamedEventHandler(0, Watcher::OnRenamed);
Now because i have given the absolute name for the filter, upon renaming the handlers wont be invoked
because it is still searching for the orignal file name, so what i need to do is update the watcher->filter inside the rename handler in order to keep the file being monitored :S
There is a way to get around this but it is not the best idea. Normally the fact that you have to get around this is either a product of bad design or of being forced to use an API which forces C style callbacks as opposed to the observer/listener paradigm via interfaces.
Hm, deja vu...
Did you have any problems with the bold part?In C++ there is no other way than having static versions of those functions. The first parameter should hold a reference to your filesystemwatcher object so you can have a static lookup table to connect the filesystem watcher object to another class or subclass the watcher class so you can call one of it's new methods.
Please note that those difficulties are due to your use of C++/CLI. If you need .NET use a native .NET Language like C# and you won't have those problems.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Even if it isn't C++ the same 'trick' works but I won't post it b/c I don't recommend it.
The documentation says the object is the FileSystemWatcher that raised the event, so you can simply cast it. I haven't tested it though.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
thanks alot guys got it working, give me a shout if you guys want to see how i did it (nothing that great anyway).
btw it is C++ not C#
i am telling you its C++!
FileSystemWatcher Class (System.IO)
Nope - see here.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }