1

C ++で変数を作成することは可能ですか?変数は、使用されるたびに異なる値に展開されますか?

たとえば、次のことが必要です

#define mytype [smth here]
void foo(mytype a,mytype b,mytype c)

に展開されます

void foo(mytype1 a,mytype2 b,mytype3 c)

また

void foo(mytype1 a,mytype11 b,mytype111 c)
4

4 に答える 4

0

If it should only increase when outputting, you can define a struct overriding the operator<<, e.g.:

struct myvarstruct {
  int i;
  myvarstruct() : i(1){}
} myvar;

ostream &operator << (ostream &o, myvarstruct &s) {
  return o << "myvar" << s.i++;
}
于 2013-11-14T15:00:14.383 に答える
-1
#define mytype [smth here]
#define TYPE(a, b) _TYPE(a, b)
#define _TYPE(a, b) a##b
void foo(TYPE(mytype, 1) a, TYPE(mytype, 2) b, TYPE(mytype, 3) c)
于 2013-11-14T15:34:38.473 に答える