Burnie Burnie - 1 year ago 108
C++ Question

Calling methods from a header from another cc file?

How do you call a method from a header file that a .cpp file contains?

For example:


#include <iostream>
#include "test.h"
using namespace std;
int main() {


void sayHelloWorld();


#include "test.h"

void sayHelloWorld() {
printf("HELLO WORLD!\n");

Sorry if this seems like an easy question for some of you. :/

Pat Pat
Answer Source

Your example is the standard way of doing this. Remark: in test.cpp you'll need to #include <stdio.h> or better #include <cstdio> in order to use the printf function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download