For example, say we have this code
template<typename T>
class Base_Counter_A
{
// Only derived classes can instantiate this, to insure correct values are passed
protected:
Base_Counter_A(T TValue):
Val(TValue)
{
//implementation
}
Base_Counter_A():
Val(0)
{
//implementation
}
private:
int Val;
};
template<typename T, typename K>
class Counter : public Base_Counter_A<T>
{
public:
Counter(T TValue, K KValue)
requires(!std::is_same<T, int>::value):
Base_Counter_A<T>() // Call Default constructor
{
// implementation
}
Counter(T TValue)
requires(std::is_same<T, int>::value):
Base_Counter_A<T>(TValue) // Call overloaded Constructor
{
// Implementation
}
};
Counter<int, char> Counter_Instance(2, 10); // Error C7500: no function satisfied its constraints
Counter<int, char>(2); // Success
Counter<std::string, char> Counter_Instance("Derived", 10); // Success
What I want to do is to add information to Error C7500, explaining that a second value cannot be passed when the first type is an int.
This is purely a simplified version of what my actual code looks like. Counter actually derives from two parent classes, similarly to how it derives from Base_Counter_A.
I've considered explicit specialization, but the number of permutations is extensive. I have solved the error by using requires, but would like to streamline this process and be as informative as possible when an incorrect value is passed.
Is it possible to provide the compiler additional information when error C7500 occurs. ie. "Error: C7500, too many parameters. Parameter 2 (char) was unexpected while parameter 1 is an integer"