LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 03-29-2013, 04:09 AM   #1
akhirul
LQ Newbie
 
Registered: Mar 2013
Posts: 1

Rep: Reputation: Disabled
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
 
Old 03-29-2013, 04:28 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 3,984

Rep: Reputation: 1000Reputation: 1000Reputation: 1000Reputation: 1000Reputation: 1000Reputation: 1000Reputation: 1000Reputation: 1000
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)
 
Old 03-29-2013, 05:20 PM   #3
bloody
Member
 
Registered: Feb 2013
Location: Berlin
Distribution: Gentoo, Debian
Posts: 158

Rep: Reputation: 22
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?
 
Old 03-29-2013, 11:54 PM   #4
John VV
Guru
 
Registered: Aug 2005
Posts: 12,061

Rep: Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573Reputation: 1573
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation of C++ code with Purify henrysimon Solaris / OpenSolaris 6 06-28-2012 12:39 AM
Switches controlling the code compilation -- How to kk2202 Programming 1 08-28-2009 10:18 AM
D-ITG compilation error - me or the code? baldy3105 Linux - Software 2 12-08-2006 04:47 AM
Compilation error while mixing C & C++ code. mghiya Programming 3 04-11-2006 09:45 AM
compilation error - code 2 jhon Programming 2 08-31-2004 01:54 AM


All times are GMT -5. The time now is 02:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration