mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-10 22:16:31 +08:00
support bazel complie this project and format code.
This commit is contained in:
@@ -1,41 +1,29 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
class Base {
|
||||
public:
|
||||
};
|
||||
|
||||
};
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived() { cout << "Derived created" << endl; }
|
||||
|
||||
class Derived : public Base
|
||||
{
|
||||
public:
|
||||
Derived()
|
||||
{
|
||||
cout << "Derived created" << endl;
|
||||
}
|
||||
Derived(const Derived &rhs) {
|
||||
cout << "Derived created by deep copy" << endl;
|
||||
}
|
||||
|
||||
Derived(const Derived &rhs)
|
||||
{
|
||||
cout << "Derived created by deep copy" << endl;
|
||||
}
|
||||
~Derived() { cout << "Derived destroyed" << endl; }
|
||||
};
|
||||
|
||||
~Derived()
|
||||
{
|
||||
cout << "Derived destroyed" << endl;
|
||||
}
|
||||
};
|
||||
int main() {
|
||||
Derived s1;
|
||||
|
||||
int main()
|
||||
{
|
||||
Derived s1;
|
||||
Derived s2 = s1; // Compiler invokes "copy constructor"
|
||||
// Type of s1 and s2 are concrete to compiler
|
||||
|
||||
Derived s2 = s1; // Compiler invokes "copy constructor"
|
||||
// Type of s1 and s2 are concrete to compiler
|
||||
|
||||
// How can we create Derived1 or Derived2 object
|
||||
// from pointer (reference) to Base class pointing Derived object?
|
||||
|
||||
return 0;
|
||||
}
|
||||
// How can we create Derived1 or Derived2 object
|
||||
// from pointer (reference) to Base class pointing Derived object?
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user