I am writing a class that needs to support both volatile and non-volatile instances (volatile instances use atomic operations, non-volatile instances use regular operations), and am wondering if I am going about it in the correct way. Here's a snippit of the class declaration so far:
class Yield {
public:
Yield();
Yield(Yield const &other);
Yield(Yield const volatile &other);
Yield &operator=(Yield const &other);
Yield &operator=(Yield const volatile &other);
Yield &operator+=(Yield const &other);
Yield &operator+=(Yield const volatile &other);
Yield volatile &operator+=(Yield const &other) volatile;
Yield volatile &operator+=(Yield const volatile &other) volatile;
// Other operators snipped...
};
Question 1: When compiling with MSVC, I get the following warning:
warning C4521: 'util::Yield' : multiple copy constructors specified
Does this warning portend any problems in using this class? Or can it be safely ignored?
Question 2: As it stands, all operators are overloaded for both a volatile and non-volatile
other
argument. I assume this is necessary in order to avoid slower volatile accesses for non-volatile instances? Is there an alternative to allow each method to be coded only twice (volatile lhs and non-volatile lhs) rather than 4 times (volatile and non-volatile lhs, each with volatile and non-volatile rhs)?
I hope putting these questions together is ok, otherwise please leave a comment and I can split them. Thanks!