Data Type Modifiers

signed, unsigned, short and long
Why do data type modifiers only work on built in types?
Why can't you make a custom data type modifier?
They don't apply to all built in types.
Last edited on
The data type modifiers are a language feature used to select different properties of specific, built-in types.

C++ allows you to write your own data type modifiers in the form of templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
using namespace std;

typedef enum { friendly, unfriendly } friendliness_t;

template <friendliness_t Friendliness>
class Greeting
  {
  public:
    string greet() const
      {
      return (Friendliness == friendly)
           ? "Hello!"
           : "Get lost!";
      }
  };

int main()
  {
  Greeting <friendly>   Tim;
  Greeting <unfriendly> Tom;

  cout << "Tim says \"" << Tim.greet() << "\"\n";
  cout << "Tom says \"" << Tom.greet() << "\"\n";

  return 0;
  }

Hope this helps.
Thanks for the answer Duoas

my only complaint is I can't do
unsigned MyType x;

without doing
MyType<unsigned> x;

I would just like it if it could be overloaded.

also from your example how could I get a friendly int;

also on a side note has anyone actually used
unsigned void x;
and if so, why did you choose it over
signed void x;
Last edited on
void is neither signed nor unsigned -- you cannot specifiy it as such (according to ISO/IEC C/C++)

RLM is not part of C++.
RLM?
Last edited on
Topic archived. No new replies allowed.