Skip to content

Instantly share code, notes, and snippets.

@SyntaxColoring
Created July 3, 2018 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SyntaxColoring/ad7f7248919d7a51b10b4dbdc508d4e4 to your computer and use it in GitHub Desktop.
Save SyntaxColoring/ad7f7248919d7a51b10b4dbdc508d4e4 to your computer and use it in GitHub Desktop.
Dangerous Linkage
#include <iostream>
struct S
{
int i;
int f(int j) // Multiply.
{
return i*j;
}
};
int square(int i)
{
S s{i};
return s.f(i);
}
int times_2(int i);
int main()
{
std::cout << "square(10) = " << square(10) << std::endl;
std::cout << "times_2(10) = " << times_2(10) << std::endl;
}
struct S
{
int i;
int f(int j) // Add.
{
return i+j;
}
};
int times_2(int i)
{
S s{i};
return s.f(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment