main.CPP文件 ======= externC int function(void); class xyz { public: int(* funcptr)(void); }对象; int main(无效){ int temp = 0; 对象。 funcptr = function; //这一行给了我概率。 temp = object.funcptr(); 返回0; } second.C文件 ========= int function(void){ 返回1; } *************** 赋值funcptr = function给了我错误。实际上我是在TI的Code Composer Studio上工作的b $ b。所以我不确定错误 是否限制在那个环境中。 代码只是翻拍,只是为了呈现核心理念。 - jag Quaerendo invenietis < JA ********* @ gmail.com>在消息中写道 news:11 ********************** @ g43g2000cwa.googlegr oups.com main.CPP文件 ======= externC int function(void); class xyz { public: int(* funcptr)(void); } object; int main(void){ int temp = 0; object.funcptr = function; //这行给了我概率。 temp = object.funcptr(); 返回0; } second.C文件 = ======== int function(void){返回1; } ******** ******* 分配funcptr = function给了我错误。实际上我正在TI的Code Composer Studio上工作。所以我不确定错误是否会限制在那个环境中。 代码只是翻拍,只是为了呈现核心理念。 - jag Quaerendo inventietis 您的代码在VC ++(7.1和8.0)上编译并运行没有问题--- 它应该。如果它不能在TI的Code Composer Studio上运行,那么问题就在于 。错误信息实际上是什么意思? - John Carson Hi,I am having a CPP file which defines a class:class xyz{public:int (*funcptr)(void);}A function foo is defined in a "C file"and in the CPP file, I need to make an assignmentfuncptr = foo;So I declared foo as extern "C" in the CPP file:extern "C" int foo(void);But I am getting an error in the assignment, since one side is of type"extern C". What is the solution for this?Please do help.TIA.--jag."Quaerendo invenietis" 解决方案 <ja*********@gmail.com> wrote in messagenews:11**********************@g14g2000cwa.googlegr oups.com Hi, I am having a CPP file which defines a class: class xyz{ public: int (*funcptr)(void); } A function foo is defined in a "C file" and in the CPP file, I need to make an assignment funcptr = foo;funcptr is a member and hence only exists as part of an object. Thus youneed something likexyz obj;obj.funcptr = foo;Perhaps this is what you do, but if you don''t post real code then we can''tknow and hence can''t diagnose the problem. So I declared foo as extern "C" in the CPP file: extern "C" int foo(void); But I am getting an error in the assignment, since one side is of type "extern C". What is the solution for this?Aside from the problem described above, it should work. If the above doesn''tsolve the problem, then post the smallest complete code that exhibits theproblem (i.e., copy and paste actual code that has failed to compile).--John Carson Hi,main.CPP file=======extern "C" int function(void);class xyz{public:int (*funcptr)(void);}object;int main(void){int temp = 0;object.funcptr = function; //this line gives me the prob.temp = object.funcptr();return 0;}second.C file=========int function(void){return 1;}***************The assignment "funcptr = function" gives me the error. Actually I amworking on TI''s Code Composer Studio. So I am not sure if the errorconfines to that environment.The code is just a remake, just to present the core idea.--jag"Quaerendo invenietis" <ja*********@gmail.com> wrote in messagenews:11**********************@g43g2000cwa.googlegr oups.com Hi, main.CPP file ======= extern "C" int function(void); class xyz{ public: int (*funcptr)(void); }object; int main(void){ int temp = 0; object.funcptr = function; //this line gives me the prob. temp = object.funcptr(); return 0; } second.C file ========= int function(void){ return 1; } *************** The assignment "funcptr = function" gives me the error. Actually I am working on TI''s Code Composer Studio. So I am not sure if the error confines to that environment. The code is just a remake, just to present the core idea. -- jag "Quaerendo invenietis"Your code compiles and runs without a problem on VC++ (7.1 and 8.0) --- asit should. If it won''t run on TI''s Code Composer Studio, then it looks likethat is where the problem lies. What does the error message actually say?--John Carson 这篇关于使用函数指针类成员。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 14:42