Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


New to C++, 1st program.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
shadowclaw3
Expert Cheater
Reputation: 0

Joined: 05 Aug 2007
Posts: 114

PostPosted: Tue Apr 07, 2009 6:44 pm    Post subject: Reply with quote

ahh cool, thanks just needed to clear that.

dont think i need your msn with such fast replies lol,

thanks again.

EDIT:


Code:
// pointer to functions
#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, int (*functocall)(int,int))
{
  int g;
  g = (*functocall)(x,y);
  return (g);
}

int main ()
{
  int m,n;
  int (*minus)(int,int) = subtraction;

  m = operation (7, 5, addition);
  n = operation (20, m, minus);
  cout <<n;
  return 0;
}


im not understanding this lesson so well, can someone explain all the parts? or maybe just
int (*minus)(int,int) = subtraction;
and how to do
m = operation (7, 5, addition);
n = operation (20, m, minus);

_________________
<(~.~<) BOO!
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Apr 09, 2009 12:07 am    Post subject: Reply with quote

shadowclaw3 wrote:
im not understanding this lesson so well, can someone explain all the parts? or maybe just
int (*minus)(int,int) = subtraction;


That is a function cast. You can use it to call functions dynamically (like the address you get from using the GetProcAddress() function).

shadowclaw3 wrote:
and how to do
m = operation (7, 5, addition);
n = operation (20, m, minus);


You are passing the pointer to the start of the code of the function. The function then takes the pointer and casts it into a function, as said previously.

Also, in the future, delete your post then repost it so it gets bumped up to the top. I didn't see the edit until just now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites