?
Solved

function pointer cdecl to thiscall problem

Posted on 2010-08-31
8
Medium Priority
?
652 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

800 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