Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-10-2009
Member
 
Join Date: Jun 2009
Posts: 50
Passing function parameter and static

Code:
#include <string>
#include <iostream>
using namespace std;
struct Functor{
bool operator()(const std::string& str){cout<<str<<endl;return true;}
};
struct Functor2{
static bool compute(const std::string& str){cout<<str<<endl;return true;}
};
struct Foo
{
template<class F>
void callMe()
{
 F()("operator ()");
}
template<class F>
void callMe2()
{
 F::compute("static");
}
};
int main(int n,char ** arfv)
{
Foo obj;
obj.callMe<Functor>();
obj.callMe2<Functor2>();
system("pause");
}
If you want to pass a function parameter which method is better to use: functor or functor2?
Reply With Quote
  #2  
Old 27-10-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Passing function parameter and static

What is static over here? Static method means a state where the compiler does not allow any reentry. That means, you cannot change anything in that method or variable. In short, none of the two is recommended. The idiom favored by the standard:

Code:
template<class Fun> void callMe( Func f)
{
f("operator ()" );
}
Reply With Quote
  #3  
Old 27-10-2009
Member
 
Join Date: Jun 2009
Posts: 50
Re: Passing function parameter and static

I recently read a language such as ADA which is assumed to be better than C++ programming for parallel/concurrent. And with the next version of C++ or the development of third-lib, we can not hope that one day the C++ is doing better in this area? Any comments?
Reply With Quote
  #4  
Old 27-10-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Passing function parameter and static

Quote:
Originally Posted by Banjiji View Post
Code:
#include <string>
#include <iostream>
using namespace std;
struct Functor{
bool operator()(const std::string& str){cout<<str<<endl;return true;}
};
struct Functor2{
static bool compute(const std::string& str){cout<<str<<endl;return true;}
};
struct Foo
{
template<class F>
void callMe()
{
 F()("operator ()");
}
template<class F>
void callMe2()
{
 F::compute("static");
}
};
int main(int n,char ** arfv)
{
Foo obj;
obj.callMe<Functor>();
obj.callMe2<Functor2>();
system("pause");
}
If you want to pass a function parameter which method is better to use: functor or functor2?
do not use static data (unless they are constants), using only data from the caller, do not call next function

Regarding ADA:

Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages. Ada is strongly typed and compilers are validated for reliability in mission-critical applications, such as avionics software.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Passing function parameter and static"
Thread Thread Starter Forum Replies Last Post
Passing object as a parameter in a method Karumbu Software Development 4 06-01-2011 01:07 AM
Passing an ArrayList From the Form as Parameter Sheenas Software Development 8 20-06-2010 10:45 AM
Passing "file" parameter in a function kamina23 Software Development 3 29-10-2009 11:07 PM
Passing parameter of Oracle procedure in PHP Halina Software Development 3 22-04-2009 08:46 PM
Parameter passing using NavigateURL Sachit Software Development 3 26-03-2009 09:25 AM


All times are GMT +5.5. The time now is 01:38 AM.