Skip to content

Instantly share code, notes, and snippets.

@shunirr
Created June 13, 2012 06:16
Show Gist options
  • Save shunirr/2922187 to your computer and use it in GitHub Desktop.
Save shunirr/2922187 to your computer and use it in GitHub Desktop.
typedef struct {
int *p;
} Mashiro;
void fuga(const Mashiro& a)
{
Mashiro b = a; // コピーされる
*(b.p) = 20; // アドレスごとコピーされているので、これは a.p に影響する
}
int main()
{
Mashiro mashiro;
int i = 10;
mashiro.p = &i;
fuga(mashiro);
*(mashiro.p); // => 20;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment