News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Calling functions from other .cpp files

Started by msinfo, October 15, 2012, 05:00:39 PM

Previous topic - Next topic

msinfo

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

#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

void funSay()
{
cout << "from another file" << endl;
}


myhead.h

#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

jarod42

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.

MortenMacFly

Quote from: msinfo on October 15, 2012, 05:00:39 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.next.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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]