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

msinfo

  • 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

main.cpp

Code
#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;
}

input.cpp
Code
void funSay()
{
cout << "from another file" << endl;
}

myhead.h

Code
#ifndef _MYHEAD_H
#define _MYHEAD_H

void funSay();

#endif


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: 87
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: 9694
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:
http://forums.codeblocks.org/index.php/topic,9996.0.html

Topic locked.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ