Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

function pointer cdecl to thiscall problem

Posted on 2010-08-31
8
Medium Priority
?
657 Views
Last Modified: 2013-12-14
#include<iostream.h>
#include "cl2h.h"


nsur.cpp
------------
void main()
      {


      pcl::disp(&sum);

      }
cl1h.h
-----------
class pcl1
      {public:
      double  sum(double a,double b)
            {
            double c=a+b;
            }
      };

cl2h.h
--------
#include<iostream.h>
#include "cl1h.h"
double (pcl1::*pt2)(double,double)=&pcl1::sum;
class pcl
      {
      public:
      void disp(double (*pt2) (double,double))
            {
            double c=(*pt2)(20,30);
            cout<<"sum"<<c;
            }
      };


When I compile I get error
nsur.cpp(11) : error C2065: 'sum' : undeclared identifier
Could you please identify it
0
Comment
Question by:vallikumari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 33565505
Hi vallikumari,

IMO there are some problems in the code:

1. 'pcl::disp(&sum);' in 'main()' has to be 'pcl::disp(&pcl::sum);'
2. Make sure 'cl2h.h' is included in 'nsur.cpp'
3. Both function calls ('pcl::disp(&sum);' and 'double c=(*pt2)(20,30);') are written as if you intended to use static functions instead of member functions - so you either have to implement these functions to be static functions or you need to instantiate objects of the classes and call the functions against them ...
4. 'pcl1::sum' needs to return the value 'c'

ZOPPO
0
 

Author Comment

by:vallikumari
ID: 33565633
#include<iostream.h>
#include "cl2h.h"
void main()
      {
      pcl::disp(&pcl::sum);
      }
#include<iostream.h>
#include "cl1h.h"

class pcl
      {
      public:
            
            
      void disp(double (*pt2) (double,double))
            {
            pcl1 p;
            double c=p.(*pt2)(20,30);
            cout<<"sum"<<c;
            }
      };
class pcl1
      {
      public:
 double   sum(double a,double b)
            {
            double c=a+b;
      return c;
      }
      };
modified the code as per you have said but, then it is giving the following errors
c:\documents and settings\administrator\desktop\npro\cl2h.h(12) : error C2059: syntax error : '('
c:\documents and settings\administrator\desktop\npro\cl2h.h(13) : error C2039: 'cout' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\cl2h.h(13) : error C2297: '<<' : illegal, right operand has type 'char [4]'
c:\documents and settings\administrator\desktop\npro\cl2h.h(13) : error C2039: 'c' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2039: 'pcl' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2039: 'pcl' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2653: 'pcl' : is not a class or namespace name
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2039: 'disp' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2039: 'pcl' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2039: 'pcl' : is not a member of 'pcl1'
        c:\documents and settings\administrator\desktop\npro\cl1h.h(2) : see declaration of 'pcl1'
c:\documents and settings\administrator\desktop\npro\nsur.cpp(8) : error C2653: 'pcl' : is not a class or namespace name
Error executing cl.exe.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 33565677
'cout' is declared in namespace 'std', so you need to use 'std::cout'.

In the declaration of 'disp' IMO you need to declare 'pt2' to be a member function of 'pcl', somehow like 'void disp(double (pcl::*pt2) (double,double))'

Depending on you VisualStudio-version you should include <iostream> instead of <iostream.h>.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 8

Assisted Solution

by:Pramod Bugudai
Pramod Bugudai earned 200 total points
ID: 33575614
Hi. All the latest VC++ Compiler uses #include<iostream>. In that you need to include

using namespace std;  

This will remove all name confusion like std::cout.

regards
pramod

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 33575690
Well, the use of 'using namespace std;' is a matter of many discussions - I myself don't like it, at least not on a file-global scope; if any I use it within a function or a class ...

If you're interested in a detailed discussion about the 'using namespace std;' you can take a look here: http://www.experts-exchange.com/Q_24646218.html
0
 

Assisted Solution

by:vallikumari
vallikumari earned 0 total points
ID: 34674117
I have solved this
0
 

Author Comment

by:vallikumari
ID: 34674154
aa
0
 

Author Closing Comment

by:vallikumari
ID: 34709714
no
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question