-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,105 @@ | ||
class Parent { | ||
private: | ||
int a; | ||
protected: | ||
int b; | ||
public: | ||
int c; | ||
int d; // Shadowed by Child::d, but should be reachable with a cast | ||
private: | ||
int a; | ||
|
||
Parent(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {} | ||
protected: | ||
int b; | ||
|
||
public: | ||
int c; | ||
int d; // Shadowed by Child::d, but should be reachable with a cast | ||
|
||
Parent(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) | ||
{ | ||
} | ||
}; | ||
|
||
class Child : public Parent { | ||
public: | ||
int d; | ||
int e; | ||
int f; | ||
public: | ||
int d; | ||
int e; | ||
int f; | ||
|
||
Child(int a, int b, int c, int d, int e, int f) : Parent(a, b, c, d), d(d + 1), e(e), f(f) {} | ||
Child(int a, int b, int c, int d, int e, int f) | ||
: Parent(a, b, c, d), d(d + 1), e(e), f(f) | ||
{ | ||
} | ||
}; | ||
|
||
class LittleChild : public Child { | ||
public: | ||
int g; | ||
public: | ||
int g; | ||
|
||
LittleChild(int a, int b, int c, int d, int e, int f, int g) : Child(a, b, c, d, e, f), g(g) {} | ||
LittleChild(int a, int b, int c, int d, int e, int f, int g) | ||
: Child(a, b, c, d, e, f), g(g) | ||
{ | ||
} | ||
}; | ||
|
||
struct Top { | ||
int x; | ||
}; | ||
|
||
struct Left : public Top { | ||
int y; | ||
}; | ||
|
||
struct Right : public Top { | ||
int z; | ||
}; | ||
|
||
struct Bottom : public Left, public Right { | ||
int w; | ||
}; | ||
|
||
struct Multi : public Parent, public Top { | ||
int abc; | ||
|
||
Multi(int a, int b, int c, int d, int e) | ||
: Parent{ a, b, c, d }, Top{ e }, abc{ e + 1 } | ||
{ | ||
} | ||
}; | ||
|
||
int func_1(Child &c, Parent &p __attribute__((unused))) | ||
{ | ||
return dynamic_cast<Parent&>(c).d; | ||
return dynamic_cast<Parent &>(c).d; | ||
} | ||
|
||
int func_2(LittleChild &lc) | ||
{ | ||
return dynamic_cast<Parent&>(lc).d; | ||
return dynamic_cast<Parent &>(lc).d; | ||
} | ||
|
||
int func_3(Multi &m, Bottom &b __attribute__((unused))) | ||
{ | ||
return m.abc; | ||
} | ||
|
||
int main(void) | ||
{ | ||
Parent p{1, 2, 3, 4}; | ||
Child c{1, 2, 3, 4, 5, 6}; | ||
Parent p{ 1, 2, 3, 4 }; | ||
Child c{ 1, 2, 3, 4, 5, 6 }; | ||
func_1(c, p); | ||
|
||
LittleChild lc{1, 2, 3, 4, 5, 6, 7}; | ||
LittleChild lc{ 1, 2, 3, 4, 5, 6, 7 }; | ||
func_2(lc); | ||
|
||
Multi m{ 1, 2, 3, 4, 5 }; | ||
Bottom b{ | ||
{ | ||
// Left | ||
{ 1 }, // Left's Top | ||
2 // Left's y | ||
}, | ||
{ | ||
// Right | ||
{ 3 }, // Right's Top | ||
4 // Right's z | ||
}, | ||
5 // Bottom's w | ||
}; | ||
func_3(m, b); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters