Author Topic: Calling functions from other .cpp files  (Read 9487 times)


  • Guest
Calling functions from other .cpp files
« on: October 15, 2012, 05:00:39 pm »
Hello Experts,
I am newbie in C++ (code blocks too).
I am calling one function (funSay) from input.cpp file to main.cpp file, but it won't run because of undefined reference error.
Kindly refer image for actual code and error message


Code: [Select]
#include <iostream>         // helps with input and out put related tasks
#include <limits>   // helps to use max and min functions
#include <ctime>   // helps to use time functions
#include <time.h> // help with time functions
#include "myhead.h"

using std::time_t;
using std::time;
using std::localtime;
using std::asctime;

using namespace std;  // helps to use cout and cin

void funSay();
void funinput();
void funVariable();
void funTime();

int main()
cout << "Hello world!" << endl;
funSay();          // calls function named funVariable
return 0;

Code: [Select]
void funSay()
cout << "from another file" << endl;


Code: [Select]
#ifndef _MYHEAD_H
#define _MYHEAD_H

void funSay();


Second, how do i upload image, code, quote in forum text.
Clicking on given options only seems to add [img] kind of text only.
Even when my post shows 0 count, I still get error message
"You already submitted this post! You might have accidently double clicked, or tried to refresh."

With regards : Msinfo
« Last Edit: October 15, 2012, 05:02:15 pm by msinfo »

Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 82
Re: Calling functions from other .cpp files
« Reply #1 on: October 15, 2012, 05:31:12 pm »
I suspect that you don't have project.
You should create a project with all needed files (main.cpp, input.cpp, myhead.h)

And for the posting Question:
After clicking on button (Insert Image), you have to write the url corresponding to your image.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9594
Re: Calling functions from other .cpp files
« Reply #2 on: October 15, 2012, 05:40:44 pm »
I am newbie in C++ (code blocks too).
Sorry, but this is the wrong forum. There are plenty of C++ forums around that can help you with this type of questions. This forum is about Code::Blocks, an IDE - NOT about general programming issues.

If you have questions related to Code::Blocks (like how to configure a compiler, how to use the interface or alike) feel free to post here.

BTW: When registering with the forums you were notified about the forum rules which you just skipped probably. So please read here:,9996.0.html

Topic locked.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: