error in my code

Friend classB.h: No such file or directory.

Page 1 of 1

4 Replies - 483 Views - Last Post: 31 January 2010 - 06:57 AM Rate Topic: -----

#1 mon mon  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 128
  • Joined: 31-December 09

error in my code

Posted 31 January 2010 - 04:58 AM

//Example1 calling member data of a friend class
#include<iostream>
using namespace std;

class A{
	  private:
			  int x;
	  public:
			 A(){
				 cout<<"constructor A\t"<<endl;
				 }
			 ~A(){
				  cout<<"Destructor A\t"<<endl;
				  }
				  friend class B;
				  
};

class B{
	  public:
			 B(){
				 cout<<"constructor B"<<endl;
				 }
			~B(){
				 cout<<"Destructor B"<<endl;
				 }
			 void Func1(A&a)//passing object is preferred to be by address
			 {
						   cout<<"inside class B,please Enter value of x:\t"<<endl;
						   cin>>a.x;
						   cout<<"value of x is:\t"<<a.x<<endl;
			 }
};
		 
#include<iostream>
#include "Friend classB.h"
int main(){
	A a;
	B b;
	b.Func1(a);
	system("pause");
	return 0;
}								   



error is
\Users\go\Documents\examples of c++OOP\lec 8_friend member data.cpp C:\Users\go\Documents\examples of c++OOP\C Friend classB.h: No such file or directory.

**Mod Edit: Changed title to be more descriptive**

This post has been edited by OliveOyl3471: 31 January 2010 - 01:52 PM


Is This A Good Question/Topic? 0
  • +

Replies To: error in my code

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: error in my code

Posted 31 January 2010 - 05:16 AM

First of all, you are including <iostream> twice, which is not needed. Secondly, the compiler can't find "Friend classB.h" header file. Maybe check for correct header file name?
Was This Post Helpful? 0
  • +
  • -

#3 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: error in my code

Posted 31 January 2010 - 06:24 AM

Take the <iostream> and "Friend classB.h" includes away before the main function and the program should run. Unless inside the code tags is code from two files. In that case your "Friend classB.h" include should be the name of the file where the classB is located.

Why to use system("Pause"); i've never understood why and it never compiles for me.

This post has been edited by TMKCodes: 31 January 2010 - 06:26 AM

Was This Post Helpful? 0
  • +
  • -

#4 dave007  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 49
  • Joined: 24-January 10

Re: error in my code

Posted 31 January 2010 - 06:39 AM

View PostTMKCodes, on 31 Jan, 2010 - 05:24 AM, said:

Why to use system("Pause"); i've never understood why and it never compiles for me.


By using system("PAUSE"); it keeps the consol window open and give the message "Press to continue...". If you are using Editors like DevCPP and not using the system("PAUSE") it will run the program and imediately closes the window. So user doesn't get the chance to look at the output.

So it does nothing more than just wait for the user to press the key to exit the program.. :)
Was This Post Helpful? 0
  • +
  • -

#5 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: error in my code

Posted 31 January 2010 - 06:57 AM

Ah, yeah. It must be that i have never had to use it and it does not work in linux, but thanks for informing me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1