|
error generated
error C2039: 'set' : is not a member of 'std'
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Le@rner wrote: error C2039: 'set' : is not a member of 'std'
You should #include <set>
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
thanks
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Extracting numbers from a bag...
const int N = 20;
int num[N];
int i;
for (i=0; i<N; i++)
{
num[i] = i+1;
}
for (int i=0; i<N-1; i++)
{
int r = rand() % (N-i);
int temp = num[N-1-i];
num[N-1-i] = num[r];
num[r]= temp;
}
for (i=0; i<N; i++)
{
cout << num[i] << endl;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Le@rner wrote: i want to generate random number but not repeated.
Something like:
void main( void )
{
int array[10] = {0};
int n = 10;
for (int i = 0; i < n; i++)
array[i] = i;
random_shuffle(array, array + 10);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Assume there's a system with 2 objects. An object of class Boss and an object of class Worker. The object Boss does what all bosses do: tell workers what to do, drive big cars and stare out of the window. The same is true for the object Worker. It does what all workers do: staring the whole day at the screen (or out of the window) and try to solve all those silly things their boss came with. During this dull life the object Worker has one periodic highlight: Once a month it calls the object Boss and invokes the method GetSalary(). But for the Object Boss this is a big security risk: It only wants that real workers get salary.
So the problem is: a method is invoked but the object of that method wants to be sure that only specific objects may invoke that method. How to solve this?
Variables and functions may be defined as static, restricting their visibility to the module-level. Classes and methods may also use techniques like this but this is not going to work: Our object Boss is an 'interim': He's only added to a project when needed and if they pay him enough. The object Boss is a generic one.
I'm looking for solutions that can withstand a malicious programmer that creates his own object Worker or derives one from the class Worker to invoke GetSalary() as much as possible.
Another variant of this problem is an object that can be cloned but wants to do this only when asked from certain other objects (because it carries sensitive data) although its Clone-method is public.
Any suggestions? Concepts will be appreciated above code.
|
|
|
|
|
Conceptual answer: Didn't the boss hire the worker in some way? The boss should ideally be the manager for all the employees, that is, the boss should keep track of which workers that are entitled to salaries ...
|
|
|
|
|
|
in the method GetSalary(),the boss should check the worker is the real worker.
you should make some mechanism to check the real worker.
|
|
|
|
|
Iceman See my response to Adam.
|
|
|
|
|
The answer as par my design is:-
I believe boss should keep a base class Worker, with two derived classes, GoodWorker and BadWorker.
Now Boss can call based on the work
int workerCategory()
{
if( "good" == work )
{
Worker* pWorker = new GoodWorker();
}
pWorker->GetSalary();
}
class Worker
{
public:
void Work();
virtual void GetSalary();
};
class GoodWorker
{
public:
void Work()
{
}
void GetSalary()
{
...... Logic
}
};
class BadWorker
{
public:
void Work()
{
}
}
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks for your replies. I try to answer you all 3 at once:
First Matias: In real life a worker will be hired first, and this salary-thing wouldn't be a problem. Problem is that in my example there is only a boss and some workers. If you have access to this system you could easily derive a class from Worker (sub-class, inherit from, however you name it) that would have malicous code; so the worker gets salary twice a day.
Adam: I like your idea to make derived classes good worker and bad worker but i don't see how this can solve the problem: deriving a malicious class from Goodworker would be even simpler. But the idea to create a Badworker too is intriguing and maybe usefull, but i don't see how yet.
Iceman: I myself was thinking the same way, and maybe you can help me with some more ideas.
What i want is a worker-class that can not be tampered with. So it may not be derived and there may not be a another class that can have the same name. If I create Getsalary() like thiis: (in pseudo-code)
Class Boss
method Getsalary(oworker)
...
We can ensure that the argument oworker must be of class Worker (or a derived class) by strongtyping oworker. I found a way to check if oworker is not a derived one. And here OO stops: Boss can not be sure if it is the 'right' untampered version of Worker or just a fake.
I was thinking to implement some kind of shared secret, when the worker ask Salary it must solve a riddle first.
If the source of both objects is known this will not work, so at least one of them must be published in a DLL (or something) that hides the solving of the riddle...
Placing code in a DLL is not a strong one (you can replace it). So i need really good ideas how to create this kind of security.
Maybe it is possible to do some variable encryption, like this:
Boss calls a method of Worker. This decrypts a internal piece of data in Worker, Worker sends this data when it invokes Getsalary. Boss checks this data. If the data was ok salary is paid otherwise not.
Feel free to give me more suggestions and thanks so far...
|
|
|
|
|
Hi Gurus,
I am looking for an C++ subroutine for integration, accurate one.
Thanks
|
|
|
|
|
|
I mean mathematical integration of an array, e.g. integrate velocity waveform into displacement waveform.
Or integrate area under a curve y=f(x)
|
|
|
|
|
Ok, easy answer: there's no general library for integrals (as far as I know). Numerical integration is a vast area, and what approach to use totally depends on the problem at hand. Did you try this link?
|
|
|
|
|
If i have a assembly file, how do I compile that in Visual Studio? Is it even possible? If it's not, what are my options? I've never done something like this, so I'm pretty clueless about assembly, other than a basic understanding of how to read it.
|
|
|
|
|
Never mind, ML is apparently what I want to use.
|
|
|
|
|
Hi all
i am get guide from codeproject and codeguru for create dll WH_KEYBOARD. Code is here
#include "stdafx.h"
#include "Testdll.h"
#pragma data_seg(".HOOKDATA")//Shared data among all instances.
HHOOK hook = NULL;
HWND hwnd = NULL;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")//linker directive
HINSTANCE hinstance = NULL;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
hinstance = (HINSTANCE)hModule;
hook = NULL;
return TRUE;
}
Testdll_API void installhook(HWND h)
{
hook = NULL;
hwnd = h;
hook = SetWindowsHookEx(WH_KEYBOARD,hookproc,hinstance,NULL);
if(hook==NULL)
MessageBox(NULL,"Unable to install hook","Error!",MB_OK);
}
Testdll_API void removehook()
{
UnhookWindowsHookEx(hook);
}
Testdll_API LRESULT CALLBACK hookproc(int ncode,WPARAM wparam,LPARAM lparam)
{
if(ncode>=0)
{
if((lparam & 0x80000000) == 0x00000000)
{
hwnd = FindWindow("#32770","TestDialog");
PostMessage(hwnd,WM_USER+755,wparam,lparam);
}
}
return ( CallNextHookEx(hook,ncode,wparam,lparam) );
}
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif
TESTDLL_API void installhook(HWND h);
TESTDLL_API void removehook();
TESTDLL_API LRESULT CALLBACK hookproc(int ncode,WPARAM wparam,LPARAM lparam);
It is compile successful.
Now i am using this dll in testdlg.Then dialog hang.
installhook(this->GetSafeHwnd());
Can any one tell me where i am wromg.
Plz help me
|
|
|
|
|
Where does your application hang? At what function call? Have you tried setting a breakpoint and stepping through the code?
|
|
|
|
|
Thanks for response and sorry for late from my side.
I have try to debug and i found where my application is going to hang.
installhook(this->GetSafeHwnd());
|
|
|
|
|
It crashes when doing the actual function call? Hmmm ... Can you call anything in the DLL? Try calling a function returning void with no arguments, to eliminate problems with calling conventions and stuff like that. Does DllMain get called properly?
/M
|
|
|
|
|
I want to be able to disable the UI for an ActiveX control while certain processing is happening. Is there a way to "gray-out" the entire control without having to disable each individual button or field in the control?
|
|
|
|
|
Why don't you do the processing in a background thread, and maintain a responsive UI (and perhaps offer the user a way to abort the process)?
L u n a t i c F r i n g e
|
|
|
|
|
Processing will be done on a background thread, and in most cases, I do wish to maintain a responsive UI. But in some cases, I need to visibly disable the UI and was hoping for some magic options that wouldn't require disabling each control individually.
|
|
|
|