Skip to content

Instantly share code, notes, and snippets.

@benvanik
Last active July 18, 2017 14:58
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 benvanik/a38ae821d6ccfdb5b4a206d2ef11cf09 to your computer and use it in GitHub Desktop.
Save benvanik/a38ae821d6ccfdb5b4a206d2ef11cf09 to your computer and use it in GitHub Desktop.
bzlrepro
#include "a.h"
A::A() = default;
A::~A() = default;
int A::QueryX() { return x; }
#ifndef A_H_
#define A_H_
constexpr int kReallyX = 7;
class A {
public:
A();
~A();
int QueryX();
int x = kReallyX;
};
#endif // A_H_
#include "b.h"
B::B(A* a) : a(a) {}
B::~B() = default;
int B::QueryY() { return a->QueryX(); }
#ifndef B_H_
#define B_H_
#include "a.h"
class B {
public:
explicit B(A* a);
~B();
int QueryY();
A* a;
};
#endif // B_H_
package(default_visibility = ["//visibility:public"])
cc_library(
name = "a",
srcs = ["a.cc"],
hdrs = ["a.h"],
)
cc_library(
name = "b",
srcs = ["b.cc"],
hdrs = ["b.h"],
deps = [":a"],
)
cc_binary(
name = "c",
srcs = ["c.cc"],
deps = [":b"],
)
cc_binary(
name = "d",
srcs = ["d.cc"],
deps = [":b"],
)
#include <cstdio>
#include "b.h"
int main() {
A a;
B b(&a);
printf("%d", b.QueryY());
return 0;
}
#include <cstdio>
#include "b.h"
int main() {
A a;
B b(&a);
printf("kReallyX = %d\n", kReallyX);
printf("B.QueryY() = %d\n", b.QueryY());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment