|
Hi All
I'm getting some error in below code. can any body tell me whats is the proboem in my code?
Test.h
---------------
class Test
{
private:
int i , j;
public:
//f pointer
int f1(int i, int j);
int f2(int i, int j);
int (*fptr)(int,int);
};
Test.cpp
-----------------
int Test::f1(int i, int j)
{
int res = i+j;
cout<<"IM IN f1 : Reult "<<res<<endl;
return res;
}
int Test::f2(int i, int j)
{
int res = i-j;
cout<<"IM IN f2 : Reult "<<res<<endl;
return res;
}
main.cpp
------------
int main()
{
Test obj;
int (*fptr)(int,int) ;
fptr = &(Test::f1);
fptr(2,1);
return 0;
}
Actually im getting error in fptr = &(Test::f1); line
i.e Error 1 error C2440: '=' : cannot convert from 'int (__thiscall Test::* )(int,int)' to 'int (__cdecl *)(int,int)' c:\documents and settings\e_skanun\my documents\visual studio 2005\projects\test\test\main.cpp 35
And im nt able to correct.
plz do help.
Regards
Phillip
Regards
Phillip
|
|
|
|
|
Global functions and class member functions do not have the same signature: for a function member of a class, the this pointer is passed implicitely to identify the instance of the class on which the function is called.
What you are trying to do there is store a pointer to a member function in a pointer to a global function. So, that's why the compiler complains that you cannot do that.
EDIT: oops, I misread your code sorry. David's answer is correct.
modified on Thursday, March 19, 2009 9:07 AM
|
|
|
|
|
Cool_Phillip wrote: int (*fptr)(int,int) ;
Change this to:
int (Test::*fptr)(int, int); Cool_Phillip wrote: fptr(2,1);
Change this to:
(obj.*fptr)(2,1);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thanx its working now.
Regards
Phillip
|
|
|
|
|
That's because &(Test::f1) is not a int (__cdecl *)(int,int) and cannot be converted to one. All non-static methods have an extra, implicit parameter, the object pointer. And, just to make things more complex, the object pointer isn't passed like other parameters, so trying to use a function pointer of int (__cdecl*)(Test*, int, int) won't work either.
Instead, you need to make fptr a method pointer, and call it with the special 'method pointer' syntax - replace your main with this one:
int main()
{
Test obj;
int (Test::*fptr)(int,int) ;
fptr = &(Test::f1);
(obj.*fptr)(2,1);
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Now that you know how to do it, may I ask why do you need to do it?
[added]
Well, I suppose my curiosity was not opportune...
[/addded]
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]
modified on Thursday, March 19, 2009 1:27 PM
|
|
|
|
|
Actually i had some doubt about function pointer. thats why i wrote this code and try tried to run.
Regards
Phillip
|
|
|
|
|
OK, thank you.
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]
|
|
|
|
|
This is a big question that covers both building & source-control of programs.
I use Perforce (they don't have forums) as my CVS source-control. Does anyone have any good ideas on how to write a batch-process to:
1. Sync to a specific changelist (collection of versions) in Perforce
2. Use MS VC6 to batch build (consists of multiple projs of dlls/exes) and might need rebuild/relink due to dependencies.
3. Once 100% built (rebuild doesn't do any further linking) then move to folder with same name as the changelist #.
4. Repeat from step 1 onto the next changelist.
|
|
|
|
|
At my last place of employment, we put together a set of batch files that would run nightly to check files out of SourceSafe, compile each module, and then check files back in. All errors were captured in a log file that got looked at the next day.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Never used perforce. Have used Ant and I recommend it. That said check this out[^]
|
|
|
|
|
CruiseControl.net with Nant can probably solve your needs.
|
|
|
|
|
hmm, looks cool
does ant, cruise control work with C++
I've searched but still can't find any references to C++
|
|
|
|
|
CruiseControl main purpose is to get the latest version of the source from the version-control-system, and start building the solution using the latest source (Independent of the programing language used in the solution)
Nant is merely a "script" language to specify how the build proces should be performed. You can call the VC6 compiler from nant, and that way build the solution.
|
|
|
|
|
Hi,
We have VC++ application running on server which goes down sometime. Is there any inbuild tool which run on my desktop and do the monitoring of xyz.exe (running on server) from task manager.Please let me know if you know any such tool. Appreciate your time.
Thanks
Pankaj
|
|
|
|
|
Define 'monitoring'. I have many, many monitoring tools that monitor different aspects of process behaviour (RegMon, FileMon, ProcMon, TcpView, Wireshark, etc etc).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Just to monitor whether xyz.exe is running or stopped. Either by showing status as green when exe is running and Red when exe stop on client desktop.
|
|
|
|
|
Task manager?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Task Manager display on server where exe run however I need something show on my desktop.
|
|
|
|
|
In that case, I'd suggest pslist[^], as it can list the processes running on a remote computer. It's free, it's sanctioned by Microsoft and (like all the other SysInternals tools) it gets the job done!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
How about Remote Task Manager?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
How about using EnumProcesses to check if your exe is listed in the process names?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
hi All,
If i want to use LoadLibrary function to import a dll and i dont want to give static path and just give dll name so where i should put my dll in system 32 or somewhere else.....and should i register it or not...please tell me.
Thanks A Ton
Ash_VCPP
|
|
|
|
|
Like this:
HINSTANCE hInst;
hInst= LoadLibrary("SayItsMyLib");
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
i tried this way but its not working...where i should keep my dll any specific location like system32?
Thanks A Ton
Ash_VCPP
|
|
|
|