Solved

can I CALL c++ METHODS FROM  A c PROGRAM ?

Posted on 2000-02-24
2
183 Views
Last Modified: 2010-04-02
HI,

can I CALL c++ METHODS FROM  A c PROGRAM ?

THANKS in advance.


0
Comment
Question by:tridev
  • 2
2 Comments
 
LVL 3

Expert Comment

by:Norbert
ID: 2553641
without any atribute - no
C++ mangles functionnames to code parametertype, number of parameters and so on to the function name. - That is the reason why function names looks so cryptic if the linker detects unresolved external functions.
But to switch of this mageling you can declare a function as
extern "C" Returntype Func(Parameter1Type P1 ,Parameter2Type P2,...,...)
in that case you only can use the features C provides.
Polimorph. functions are not possible for extern "C" declared functions. But
these functions now resides inside the C++ part they can call real C++ functons.
So you are able to write wrapper functions for the real C++ functions with full support to C++ functions
example:
Add(int Var1,int Var2, int* Result)
{
    *Result=Var1+Var2
}
Add(double Var1,double Var2, double* Result)
{
    *Result=Var1+Var2
}

extern "C" AddInt(int Var1,int Var2, int* Result)
{
    Add(Var1,Var2,Result);
}
extern "C" AddDouble(double Var1,double Var2, double* Result)
{
    Add(Var1,Var2,Result);
}
you can call AddInt or AddDouble fron C Code but you can't call Add directly from C

The example above makes no sense
because you can use + to do adding but it shows what I mean
0
 
LVL 3

Accepted Solution

by:
Norbert earned 10 total points
ID: 2553646
I forgot to switch from comment to answer.
My previous comment should be an answer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

828 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