0

I have a block of code like this:

struct CommErr {};

class C {
   virtual void Func(int i, const int *ptr, CommErr);
};

...
C c;
c.Func(i, p, {});

CommErr is not a base class/structure.

What can be the purpose of an empty CommErr structure?

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 2
    seems a dupe of [Usage of empty structs in C++](https://stackoverflow.com/questions/60685261/usage-of-empty-structs-in-c) or probably others discoverable by searching ;-) *[flagged with a worse dupe at first; d'oh]* – underscore_d Apr 27 '21 at 15:55
  • needs more context. My first idea would be to disambiuate different overloads that have identical signature otherwise by adding different "dummy" parameters, but there is only one `Str` and only one overload. – 463035818_is_not_an_ai Apr 27 '21 at 15:55
  • You can use it to force an overload to be chosen over a different one. I believe have seen this idea with boost::MultiIndex they call it tags – drescherjm Apr 27 '21 at 15:55
  • 1
    C++17 already provides a convenient empty struct for you, [`std::monostate`](https://en.cppreference.com/w/cpp/utility/variant/monostate). Another use of an empty struct is just for type tagging, like a public constructor that takes a private key (because `std::make_unique` needs the constructor to be public). – Eljay Apr 27 '21 at 15:59

0 Answers0