|
-
November 9th, 2009, 05:14 PM
#2
Re: howto restric a method to being absolutely constant
I don't understand the question. Doesn't every thread have its own instance of the functor that is completely different from every other instance that was created by other threads? If all the instances do not have any way of gaining access to each other what is the problem?
if you want a functor to be "read-only" make its operator(), function arguments, and any other private members const and the compiler will ensure that you aren't modifying anything. If you build all of your functions to be const correct there shouldn't be any problems with getting the desired behavior. Do you know about the const qualifier in C++?
Code:
bool FooClass::readOnlyFunction(const XType& xParam) const
{
// do something with xParam but can't modify it.
// also this function can't call non-const members of other objects
bool something(false);
// you can modify the something variable to indicate something
return something.
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|