Original Post
🔒 Locked
Inline Functions
Advertisement
Hm, so functions that take up only a few lines would be better as inline, but larger ones could be better as just a plain function?
Blah, it seems to be it doesnt matter that much anyway, since computers now a days are so fast.
Little functions like these would be good as inline I am guessing
Blah, it seems to be it doesnt matter that much anyway, since computers now a days are so fast.
Little functions like these would be good as inline I am guessing
class Dog{public: Dog( void ); ~Dog( void ); void Bark( void ) const; void Sleep( void ) const; void Beg( void ) const; void SetAge( unsigned short int iVal ); void SetWeight( unsigned short int iVal ); unsigned short int GetAge( void ) const; unsigned short int GetWeight( void ) const;private: unsigned short int iAge; unsigned short int iWeight;};// constructorDog::Dog( void ){ iAge = 0; iWeight = 0;}// destructorDog::~Dog( void ){}// make the dog barkinline void Dog::Bark( void ) const{ std::cout << "Your dog says Woof!" << std::endl;}// make the dog beginline void Dog::Beg( void ) const{ std::cout << "Your dog is begging for food!" << std::endl;}// make the dog sleepinline void Dog::Sleep( void ) const{ std::cout << "Your dog is sleeping!" << std::endl;}// set the age of the doginline void Dog::SetAge( unsigned short int iVal ){ iAge = iVal;}// set the weight of the doginline void Dog::SetWeight( unsigned short int iVal ){ iWeight = iVal;}// get the dogs ageinline unsigned short int Dog::GetAge( void ) const{ return iAge;}// get the dogs weightinline unsigned short int Dog::GetWeight( void ) const{ return iWeight;}Quote:
Original post by Fixxer
Hm, so functions that take up only a few lines would be better as inline, but larger ones could be better as just a plain function?
You haven't read the link, have you:
Quote:
There are no simple answers: You have to play with it to see what is best. Do not settle for simplistic answers like, "Never use inline functions" or "Always use inline functions" or "Use inline functions if and only if the function is less than N lines of code." These one-size-fits-all rules may be easy to write down, but they will produce sub-optimal results.
Quote:
Blah, it seems to be it doesnt matter that much anyway, since computers now a days are so fast.
Right you are. Make working, algorithmically optimized code first. Micro-optimize later.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement