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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inline functions

Status
Not open for further replies.

tryfekid

Programmer
Joined
Aug 16, 2001
Messages
9
Location
US
where should:

#inlcude "inline_file.i" // contains inline functions

go??? in the header file (.h) or the implementation file (.cc)?

at first i was putting it in the header file and i was getting tons of errors, then i put it in the implementation file and it worked. it works so i'm fine, but someone keeps on telling me that it should go in the header file, so i need to know which way is the correct way.

thanks.
 
Hy,
the inline functions must be in the header file (*.h).
// Inside the class pippo
{
.....
void SetStream(streambuf *pStreamBuf) {
out.ios::rdbuf(pStreamBuf);
}
......
};

Or

// Outside the class
class pippo
{
.....
void SetStream(streambuf *pStreamBuf);
......
};

inline void SetStream(streambuf *pStreamBuf) {
out.ios::rdbuf(pStreamBuf);
}

 
If you define the inline functions in the class declaration you dont need to specify the "inline" keyword.

Example

class A
{
A(){};
void SayHi(){cout<<&quot;HI&quot;<<endl;};
}

If you want to define them outside of the header but declare them as inline in the class do:

Class A
{
A(){};
inline void SayHi();
}

Now, you can declare them after the class declaration as mentioned above but I also belive that because &quot;inline&quot; was specified in the declaration, you could do it in the .cpp file as well.

matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top