由买买提看人间百态

topics

全部话题 - 话题: function
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
l**t
发帖数: 64
1
1。确定C++头文件中extern "C"声明的函数原型与C中的一致,包括参数类型在C中和C+
+中是否完全一致
2。确定这个C fuction的代码文件是用C编译器编译的,并且object文件添加到了C++工
程的连接库中
3。确定你的C++工程中其它obj中没有与这个C function同名的导出函数符号
这种问题你调试跟到c function里看一看就清楚了
b***y
发帖数: 2799
2
来自主题: Programming版 - 关于inline function里的static variable
如果定义了一个inline function, 并在多个程序文件里调用, 这个function里有stati
c variable, 如果这个funciton确实被inline了, 是不是会有多个static variable的c
opy?
c**********e
发帖数: 2007
3
For example, I have a function
Type1& func1(int x)...
How can I call the function func1()?
J*****n
发帖数: 4859
4
比如我有一个function pointer f
double (*f) (const double& p, const double& q=0);
我希望另一个函数g调用它:g(f),那么g的定义该如何写?
另一个问题是如果f的参数个数未知,那么g又该如何写?
谢谢。
g*******y
发帖数: 1930
5
how about using function objects?
define a function class with overloaded operator()
H*M
发帖数: 1268
6
来自主题: Programming版 - about STL functor and function pointers
yeah sorry my mistake
it is in cstdlib
can I conculde that all STL functions are fine with functors, and some are f
ine with function pointers at the same time?
z***e
发帖数: 5393
7
来自主题: Programming版 - about STL functor and function pointers
almost right.
c++ programming language上说stl function只是指望你给的那个能够执行 operator(
) (...)的运算,不管是function pointer还是functor.

f
d****b
发帖数: 25
8
来自主题: Programming版 - friend function 不能virtual 怎么搞呢?
但是如果有一个定义为指向base class 的指针p,后来又指向了derived class, 那么如
果用cout<<*p的话他是调用的base class的friend function, 我希望调用 derived
class的friend function. 怎么办呢?
p***o
发帖数: 1252
9
来自主题: Programming版 - friend function 不能virtual 怎么搞呢?
你在friend function里调那个virtual viod show不就完了,
当然前提是你的friend function的参数是base &而不是base。
r****t
发帖数: 10904
10
来自主题: Programming版 - Static variables in function
method 1,3 are the standard, not limited to be within function.
method 2 is a nice trick, but 初学者一定会搞错, limited in a function。
z****e
发帖数: 2024
11
再问一个问题,并祝大侠周末愉快,
我在自定义的那个function object里边加了一个cout和一个static int cnt的计数器。
发现这个function object被调用的次数,是我那个p->size()的两倍。这是为什么呢?
还是我又搞错了?
s*******e
发帖数: 664
12
来自主题: Programming版 - [合集] C++ function signature问题
☆─────────────────────────────────────☆
ilvch (From here to eternity) 于 (Mon Jun 22 19:52:58 2009, 美东) 提到:
我们经常会写返回lvalue和rvalue的access function, 比如下面的程序.
突然想到两个x1()函数的signature好象是一样的吧?
这个算overloading function么?
C++标准是怎么定义的呢?
#include
using namespace std;
class LR {
int x;
public:
LR():x(-1) {}
const int& x1() const { return x; }
int& x1() { return x; }
void print() { cout << "x = " << x << endl;}
};
int
main() {
LR lr;
int y1 = lr.x1(); // return rval
d*******n
发帖数: 524
13
so that later you can call this function by using any Container::
interator as input.
Say, I want function "f" to be called like this:
vector vi;
list ls;
......
f(vi.begin(), vi.end());
f(ls.begin(), ls.end());
I have not figured out how should I write the signature of f?
r****t
发帖数: 10904
14
来自主题: Programming版 - 基础问题:在header里面define function
在 binary 里面 define 只能一次。 declare 的东西编译器不为其生成 binary 所以可以多
次, 比如 template 这种。
你可能和我一样没有系统学过 c++,所以语言上不准确,建议拿本书看看,把名词拿准了。
没有“不是template的function”, 也没有 “用了 template的function”。名称拿准
了就不会有上面这些问题。
k*******d
发帖数: 1340
15
来自主题: Programming版 - 基础问题:在header里面define function
问题是,我有header guard,那么这个header的实际内容(也就是#ifndef #define 和
#endif之间的内容)只会被include一次吧,那么应该
function也只被define了一次啊
declare可以多次?应该也只能一次吧,完全一样的函数重复声明编译就会有错误
名词使用问题我改改吧,应该叫做function template比较确切,我是自己看C++ primer学的

以可以多
准了。
拿准
k*******d
发帖数: 1340
16
来自主题: Programming版 - 基础问题:在header里面define function
顿悟了!我原来对header guard的理解不准确,它不能保证一个header不被多个cpp所
包含。看了thrust大牛给的C++标准之后明白了, non-inline function 在一个程序里
面只能出现一次,所以不能定义在header里面。而inline和function template是可以
的。
平时用C++的时候只是按照convention来,没有学好更深层次的东西。
G****A
发帖数: 4160
17
来自主题: Programming版 - [c++] static function in a class
即使不声明为static,无论建立多少个instances,class function始终只keep一个copy。
既然这样,请问为什么只有被声明为static function 才能 be called without an
instance of the class.
D******4
发帖数: 47
18
Which allocator member function do standard containers use to acquire
storage for their elements in C++?
A. std::allocator<>::make(size_t)
B. std::allocator<>::new(size_t)
C. std::allocator<>::malloc(int)
D. std::allocator<>::allocate(size_t)
E. std::allocator<>::acquire(size_t)
我只知道D,allocate是allocator 的member function.
多谢
s*******o
发帖数: 392
19
刚开始看www.cplusplus.com上的tutorial文档,在73页写到了关于function pointer
的用
法,可是我录入后报错,希望大家帮忙看看
#include
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 x, int y)))
{
int g;
g = (*functocall(x, y));
return(g);
}
int main()
{
int m;
int (*minus)(int, int) = subtraction;
m = operation(7 , 5, minus);

std::cout << m;
system("PAUSE");
re... 阅读全帖
d**e
发帖数: 863
20
来自主题: Programming版 - why functional?

Actually the question could be rephrased as what good
does functional bring to parallel processing. I can
see the links from functional->recursion->parallel,
but not totally convinced.
P********e
发帖数: 2610
21
来自主题: Programming版 - inline function是否可以递归?
不过不应该把函数定义写在.h里,不是good practice。.h都应该只有forward
declaration, 防止不同的compilation unit有multiple definition。
用static or unnamed namespace就把函数意义改变了。
inline用法意义在class的function和free function里面不一样。
t****t
发帖数: 6806
22
来自主题: Programming版 - function in c++
function pointer is, pointer; therefore, function pointer is object.
d****n
发帖数: 1637
23
我从头到尾都没说直接swap a and b 麻烦。
其实我的版本更麻烦。希望你仔细看前面。
我的point在于,你在function 里面创建一个obj,这个cost 如果是很复杂的obj的话,
会花费
很长时间,空间。
我的工作领域里面,一个obj甚至可能被创建1million times.这就会引起问题。
如果有类似swap function, 我会考虑用pointer调换。
所以我更青睐于调用pointer。
你是抱着讨论的态度来得,对吧?
有什么不对,请您指教。
c**********e
发帖数: 2007
24
来自主题: Programming版 - C++ Q96: function inheritance (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q96: function inheritance
发信站: BBS 未名空间站 (Sun Oct 16 11:50:54 2011, 美东)
Error information in the following code is Error: equals is not a member of
B.
My question: Why equals() is not a member of B but print() is?
While this seems obvious, what is the general rule that a function will be
inherited?
#include
using namespace std;
class A {
public:
bool equal(A a) { return true; }
void print() { cout ... 阅读全帖
C***y
发帖数: 2546
25
【 以下文字转载自 JobHunting 讨论区 】
发信人: Chevy (Chevy), 信区: JobHunting
标 题: 问个C++ virtual function的问题
发信站: BBS 未名空间站 (Thu Oct 20 17:20:28 2011, 美东)
有没有办法强制基类中定义的pure virtual function在所有的继承类中实现
For example:
class A
{
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func() { std::cout<<"In B"< };
class C: public B
{
public:
void func() { std::cout<<"In C"< };
class C中也必须实现 func,否则报错
h**l
发帖数: 168
26
来自主题: Programming版 - function call?
The following code with function call can shift a string but the code
without function call can not. What might be the problem? Thanks!
_______________________________________________________
void shift(char a[])
{
int i=0;
while(a[i]) a[i] = a[++i];
}
int main()
{
char str[]= "afdd";
shift(str);
cout< return 0;
}
_____________________________________________________________
int main()
{
char str[]= "afdd";
int i=0;
while(str[i]) str[i] ... 阅读全帖
g***l
发帖数: 2753
27
来自主题: Programming版 - 请教一个C++中function pointer的问题。
一个模块,原先是在C中写的,现在要用C++重新写,因为要添加新的功能。
情况是如下:
程序运行中,能够拿到一段数据,存在连续的memory中,uint8_t *data={30,23,.....
...},data[1]用来当tag_id用,不同tag_id要调用不同对象的处理函数,data[2]是表
示数据的长度。
在原来的C中,我是建立了一个 function pointer look up table,用data[1]来搜索,
返回相应的function pointer : void(*pfunc)(uint8_t* in_data_p,uint8_t * out_
result_p).
在C++中,现在每个对象都是一个单独的class,从base class继承来的。
class base_class
{
public:
uint8_t tag_id;
std::vector result;
public:
virtual ProcessData(uint8_t * in_data_p);
};
然后每个对象的class定义如下:
clas... 阅读全帖
t****t
发帖数: 6806
28
来自主题: Programming版 - 请教一个C++中function pointer的问题。
如果我没看错的话, 你的问题不在于决定T的类型, 而是如何从tag_id产生一个T的对象
. 有了T的对象, 你就可以用virtual function直接调用ProcessData()了.
原先的关系(tag_id -> processing_function)是通过查表来定的, 说明没什么规律;
所以你现在仍然还得查表. 现在这个新的关系(tag_id -> object of T)可以通过如下
的generator function来定:
template
class_base* new_object()
{
return new T;
}
typedef class_base* (*ObjectGenerator)();
然后定义一个表格
vector generator_table;
/* or you can use map generator_map; */
generator_table = {new_object, new_object... 阅读全帖
g***l
发帖数: 2753
29
来自主题: Programming版 - 请教一个C++中function pointer的问题。
this is the complete error message. I think it is still related to function
template.
template
void register_dec_handle(int tag_id);
was declared in sample.hpp and was implemented in sample.cpp.
both class dec_1 and class dec_2 were declared in sample.hpp and implemented
in sample.cpp.
In main.cpp, #include "sample.hpp", refer to above code.
////////////////////////////////////
$g++ main.cpp sample.cpp sample.hpp -o sample
/tmp/ccPFwZuH.o: In function `main':
main.cpp:(.text+0x3f): und... 阅读全帖
j*****I
发帖数: 2626
30
来自主题: Programming版 - 弱问一个virtual function的问题
我的意思是同一个class的所有objects, function members在内存里是share的。但是
data member那份,各自有一份。
这个superclass和subclass是不是类似? subclass继承的那些non virtual function,
在内存里,实际上是指向superclass的?
p****r
发帖数: 165
31
when "Implement inline functions for retrieving function pointers to VC API
entry points",
the compiler complain:
" error C2664: 'GetProcAddress' : cannot convert parameter 2 from 'const
wchar_t [23]' to 'LPCSTR'"
it is 3rd party code suppose to work, anything I might miss? or any resource
I could take a look to help this issue? Thanks.
w********m
发帖数: 1137
32
来自主题: Programming版 - Functional programming 是大势所趋
Functional programming和Functional language其实没什么联系。
c*******9
发帖数: 9032
33
来自主题: Programming版 - Functional programming 是大势所趋
有些关系吧。Functional programming不用Functional language会比较繁琐。
b***e
发帖数: 1419
34
来自主题: Programming版 - functional programming?
That's true. I know tons of J2EE experts who used to be tailors or chefs or
mailmen from "you know where". Guess that's why people are complaining H1B
is used up. But the point is, I did never see "some of the functional
programmers cannot land a job", while I do see quite "some of the (claimed
to be) Java developers cannot land a job". I personal interviewed many Java
developers with more than 10 year experience, and they cannot write a
simple exponential function correctly.

existing.
b***e
发帖数: 1419
35
来自主题: Programming版 - functional programming?
I question the accuracy of the Haskell developer salary report, well, yes,
depending on how do you classify Haskell developers. Most of the Haskell
developers are truly academic researchers. Those people who worked with me
before are mostly tenure professors at some universities. So far I didn't
find a single case in my list of 4 big cows who's "thousand years of post-
doc". This is not biology (sorry for my candor, biologists). They might
not be making as high as 200k per year as far as ba... 阅读全帖
s***o
发帖数: 6934
36
来自主题: Programming版 - functional programming?
why is there a line drawn between functional language programmers and non
functional language programmers? It's the first time I've heard of it. It's
stupid.

straight"
b***e
发帖数: 1419
37
来自主题: Programming版 - functional programming?
That's true. I know tons of J2EE experts who used to be tailors or chefs or
mailmen from "you know where". Guess that's why people are complaining H1B
is used up. But the point is, I did never see "some of the functional
programmers cannot land a job", while I do see quite "some of the (claimed
to be) Java developers cannot land a job". I personal interviewed many Java
developers with more than 10 year experience, and they cannot write a
simple exponential function correctly.

existing.
b***e
发帖数: 1419
38
来自主题: Programming版 - functional programming?
I question the accuracy of the Haskell developer salary report, well, yes,
depending on how do you classify Haskell developers. Most of the Haskell
developers are truly academic researchers. Those people who worked with me
before are mostly tenure professors at some universities. So far I didn't
find a single case in my list of 4 big cows who's "thousand years of post-
doc". This is not biology (sorry for my candor, biologists). They might
not be making as high as 200k per year as far as ba... 阅读全帖
s***o
发帖数: 6934
39
来自主题: Programming版 - functional programming?
why is there a line drawn between functional language programmers and non
functional language programmers? It's the first time I've heard of it. It's
stupid.

straight"
r***e
发帖数: 2000
40
来自主题: Programming版 - confused over function signature C++
Now I am just totally confused here:
In a class, there are
class someclass() {
......
void foo();
void foo() const;
......
};
The question is: are these two function having the same
function signature? Or to rephrase, does 'const' change
the signature?
Is this obvious or I am just too tired?
k**********g
发帖数: 989
41

The key observation is that it needs "state", i.e. it needs to remember both
a function pointer, as well as a place to store the value of "y".
This is the first step toward understanding object-oriented programming:
variables can be captured into a structure, so that they can be accessed by
functions.
G***l
发帖数: 355
42
来自主题: Programming版 - functional programming why?
FP跟OO共存没有问题,一些简单的FP style完全可以在oo方法的内部存在,反之不是很
方便,因为object天然比较heavy,没有function简单灵活。
抛开最底层的代码共存。模块共存还是很容易的。我的个人经验是,一定要定义好功能
模块,就算纯OO也要这么做不是嘛。然后一部分模块适合fp的用fp,别的还是用oo。我
的business logic和算法很多就是纯FP的方式写的。另外有一部分有FP里面会调用OO的
模块或者class,但是把state限制的function内部。其他分就是传统的OO了,但是会在
method level有一些fp的方式或者调用fp的模块。其实写代码,最重要可维护性,可读
性,可测试,不易出错。自从我用C#和F#混合编程之后,核心代码(business logic,
算法)的维护性和可读性都提高了很多。

l**********n
发帖数: 8443
43
来自主题: Programming版 - js里,function和object的关系太抽象了
it is a dynamic language. come on. if it is an function, you can call or
apply it. otherwise an function behaves like an object. it is not a type.
there is no type in js
t**r
发帖数: 3428
44
有熟悉go的可以说说关于Package里面function如何隐藏么
一个很大的package里的function外面都可以调用,感觉不太对呢。
l*y
发帖数: 21010
45
It is better to have 100 functions operate on one data structure
than 10 functions on 10 data structures.
这句话深得我心
FP征服了我
我就讨厌屁大点事建一个类,其实都是map+list而已,
比如说数据源是json,好好的map,非要转成对象套对象,非要unmarshal,其实直接再
map上操作不就完了?
弄一大堆乱七八糟毫无意义的小类和特定类上的方法,这是导致方法不能重用的罪魁祸首
n*w
发帖数: 3393
46
来自主题: Programming版 - XSLT其实就是functional programming
xlst可以算是programming language。但是作为 functional language还缺function
as first class。有人实现了一个,还没有被w3c接受。
r*g
发帖数: 186
47
to AlphaCode 你看看我理解的对不对
感觉我这种半路出家的半吊子学C++坑太多了
以前认为C很多坑
现在觉得C++不仅继承了C的坑, 还挖了很多新的坑
我发现我C++的很多基本概念还没弄明白
常年把C++当C在用

// 所以不会有任何问题
// 首先: 根据链接:
http://en.cppreference.com/w/cpp/language/explicit
解释:
explicit operator type ( ) (since C++11)
specifies that this user-defined conversion function is only considered f
or direct initialization (including explicit conversions)
所以explicit operator S(){return S(m);}这个用户自定义转换函数只能用于direct
init,但是这里S s1 = ss; 不是direct init而是copy init:
我臆测为什么不是direct init:
因为direc... 阅读全帖
s******u
发帖数: 501
48
来自主题: Programming版 - 关于在c++ member function里用signal( )
hmm,没错,signal handler只能是函数指针,没法用bind
另外也可以用class static member function,这样不需要另外定义全局变量和free
function,当然这个handler相应的也不知道class的状态了
A********i
发帖数: 97
49
来自主题: Programming版 - 关于在c++ member function里用signal( )
这样做是不对的。The types of pointer to member function and pointer to
function are different.
https://isocpp.org/wiki/faq/pointers-to-members
链接里第二个问题给了解法,跟wdong给的一样。
s********k
发帖数: 6180
50
immutable好处确实有,但是是不是需要的存储空间会增大很多,因为任何一个变量的
值都会被存储下来?另外functional的这个function怎么理解才是最合适的,我看到有
些说把函数当做变量参数传递,这个C里面也大量用啊
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)