LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compilation error for c++ code (http://www.linuxquestions.org/questions/linux-newbie-8/compilation-error-for-c-code-4175456001/)

akhirul 03-29-2013 04:09 AM

compilation error for c++ code
 
Hi,
I am getting the below error, when i am trying to compile code below.

Error: main.cpp: In function ‚int main()‚:
main.cpp:6: error: ‚display‚ was not declared in this scope


Code:
test1.h
#include<iostream.h>
class Test
{
public:
friend int display();
};

test1.cpp:

#include<iostream.h>
int display()
{
cout<<"Hello:In test.cc"<< endl;
return 0;
}

main.cpp

#include<iostream.h>
#include<test1.h>
int main()
{
display();
return 0;
}


Strange thing is I am able to compile in unix successfully , but in linux OS getting this error.
I am using gcc and g++ compiler

pan64 03-29-2013 04:28 AM

please use [code]your code[/code] to keep formatting.
class Test is not in use at all.
I would like to see how can you compile it successfully and how it went wrong. (what was the OS, the command and the result)

bloody 03-29-2013 05:20 PM

The class refers to a function named "display" which is not defined at that point. Also, class "Test" is not created or used anywhere in the code, so why not delete the entire "class Test" thing?

John VV 03-29-2013 11:54 PM

Quote:

#include<test1.h>
from that you copied "test1.h" into /usr/include
the < > tell it to look there
and NOT in the build folder

if test1.h is in the same folder as main.cpp use
Code:

#include "test1.h"


All times are GMT -5. The time now is 08:07 PM.