2 Replies - 313 Views - Last Post: 19 May 2011 - 12:52 PM Rate Topic: -----

#1 7ragon5ly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-February 11

Calling a class from within a class

Posted 19 May 2011 - 12:42 PM

I've written a class that loads a text file.
Calling it from main is

Extra R("dream.txt");
	R.show();



but how would I call it from a different class.
Is This A Good Question/Topic? 0
  • +

Replies To: Calling a class from within a class

#2 muballitmitte  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 174
  • View blog
  • Posts: 470
  • Joined: 05-November 08

Re: Calling a class from within a class

Posted 19 May 2011 - 12:46 PM

put that that code in one of the members of the class
#include "extra.h"

class newc
{
  public:
   void method();
};

void newc::method()
{
Extra R("dream.txt");
R.show();
}


Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3030
  • Posts: 10,569
  • Joined: 08-August 08

Re: Calling a class from within a class

Posted 19 May 2011 - 12:52 PM

If you want to call the object from within another object's method, pass the object by reference. That should avoid any scope issues.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1