I am new to C++. What I am doing is creating a callback library file in C. That file will get use in C++ application. C file will have only three functions and FYI I don't want to make another cpp file/class for that because of class overhead and also classes should be in cpp file only. please go through code snippet. C file XYZ.c is using class of ABC.hpp in its function.
Allheader.hpp
#include<iostream>
.
.
ABC.hpp
#include "Allheader.hpp"
.
.
XYZ.h
func1();
func2();
func3();
XYZ.c
include "XYZ.h"
include "ABC.hpp"
func1()
{
using class of ABC here
}
func2() {}
func3() {}
MyApplication.cpp
extern "C" { #include "XYZ.h"}
.
.
So This file XYZ.c / XYZ.h will be use in My CPP application as callback.
Compiling with g++
What I have done.
- Compiled : It's Showing error, No file iostream.
As I was compiling C file and using C++ inside it started using __BEGIN_DECLS
and code in XYZ.c file was in
__BEGIN_DECLS __END_DECLS
block suggested by a colleague. But still error was the same.
How can I use C++ inside C function? Please Suggest any solution.