function help

closed account (i8bjz8AR)
So i need to create a member function to return the length of a string. it needs to return a std::size_t value. and the size() function should not change the object.

I'm compiling with g++ in the terminal so how would i do this in a .cpp and .hpp file? would it look something like this? really confused on this function.

 
size_t length() const noexcept;
What is so confusing?

If it returns just one value you may make it inline:
1
2
3
4
size_t length() const noexcept
{
  return my_length;
}
Topic archived. No new replies allowed.