Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie wants something explaining 1

Status
Not open for further replies.

jonnyknowsbest

Technical User
Feb 3, 2004
163
GB
I am learning C++ and directx but i am struggling with one aspect. What is the difference between accessing methods using a period (.) and using this ->.

Eg. if (FAILED (m_pD3D->GetAdapterDisplayMode (D3DADAPTER_DEFAULT,
&d3ddm) ) )
{
return E_FAIL;
}
 
The difference in what you're operating on.

foo-> is used when foo is a pointer to some class (or struct).
foo. is used when youre operating on the class/struct instance directly, or through a reference.

Example
Code:
Class Foo
{
  public:
    void Bar() { ... }
};

void SomeFunction(Foo& f)
{
	// f is a reference to Foo. Using . to access methods
	f.Bar();
}
void SomeOtherFunction(Foo* f)
{
	// f is a pointer to Foo. Using -> to access methods
	f->Bar();
}
...
{
	Foo foo;
	// Operating on foo directly using .
	foo.Bar();
	SomeFunction(foo);
	SomeOtherFunction(&foo);
}


/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top