I am in the process of changing a C file to a C++ file (to eventually integrate it with a C program). I'm very new to C++ and in fact this is my first exposure to it. I have a test.cpp file that declares function main and hello as follows:
#include "test.h"
int main()
{
hello ();
return 0;
}
void hello()
{
std::cout << "Hello there!" << endl;
}
The test.h file is declared as follows:
#include <iostream>
extern "C" void hello();
When I compile the program using g++ test.cpp, I get the error "hello was not declared in this scope".
Any suggestions?
Also, where does one find the API for C++ classes and their functions?
.c
source file, so you compile them as C, and declare them extern "C" from your C++ source files. Put some #ifdef __CPLUSPLUS around the "extern C" in .h files so you can include them from both languages; check the standard include files for examples. – Guntram Blohm