diff --git a/ClassMembers/.cproject b/ClassMembers/.cproject new file mode 100644 index 0000000..3cb6d55 --- /dev/null +++ b/ClassMembers/.cproject @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClassMembers/.project b/ClassMembers/.project new file mode 100644 index 0000000..b0641b7 --- /dev/null +++ b/ClassMembers/.project @@ -0,0 +1,27 @@ + + + ClassMembers + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ClassMembers/src/ClassMembers.cpp b/ClassMembers/src/ClassMembers.cpp new file mode 100644 index 0000000..9aeab95 --- /dev/null +++ b/ClassMembers/src/ClassMembers.cpp @@ -0,0 +1,107 @@ +//============================================================================ +// Name : ClassMembers.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Demonstrates shadowing and overriding of members and object sizes +//============================================================================ + +#include +#include +#include + +using namespace std; + +class Base { +public: + Base(const string& name_) : name(name_) { cout << "Base(const string& name_) :" << name << endl; } + ~Base() { cout << "~Base() :" << name << endl; } + void signal() const { cout << "Base::signal : " << name << endl; } + const string name; +}; + +class Derived : public Base { +public: + Derived(const string& name_) : Base(string("Derived::").append(name_)) { cout << "Derived(const string& name_) : " << name << endl; } + ~Derived() { cout << "~Derived() :" << name << endl; } + void signal() const { cout << "Derived::signal : " << name << endl; } +}; + +//Class with vitual methods +class Base2 { +public: + Base2(const string& name_) : name(name_) { cout << "Base2(const string& name_) :" << name << endl; } + virtual ~Base2() { cout << "~Base2() :" << name << endl; } + virtual void signal() const { cout << "Base2::signal : " << name << endl; } + virtual void signal2() const { cout << "Base2::signal2 : " << name << endl; } //warning: ‘virtual void Base2::signal2() const’ was hidden [-Woverloaded-virtual] + const string name; +}; + +class Derived2 : public Base2 { +public: + Derived2(const string& name_) : Base2(string("Derived2:").append(name_)) { cout << "Derived2(const string& name_) : " << name << endl; } + virtual ~Derived2() { cout << "~Derived2() :" << endl; } + virtual void signal() const override { cout << "Derived2::signal : " << name << endl; } + void signal2(int i) const { cout << "Derived2::signal2(int i) : " << name << " " << i << endl; } //warning: ‘virtual void Base2::signal2() const’ was hidden [-Woverloaded-virtual] +}; + +int main() { + { + cout << "**** Construct class Base instance base: 'First' ****" << endl; + Base base{"First"}; + cout << "**** Call signal from base ****" << endl; + base.signal(); + cout << "**** Construct class Derived instance derived: 'Second' ****" << endl; + Derived derived{"Second"}; + cout << "**** Call signal and shadowed ****" << endl; + derived.signal(); + derived.Derived::signal(); + derived.Base::signal(); + cout << "**** Assign &base to Base* basePtr and call basePtr->signal() ****" << endl; + const Base* basePtr = &base; + basePtr->signal(); + cout << "**** Assign &derived to Base* basePtr and call basePtr->signal() ****" << endl; + basePtr = &derived; + basePtr->signal(); + cout << "**** !!!member of Base is visible in derived!!!" << endl; + cout << derived.name << endl; + cout << derived.Derived::name << endl; + cout << derived.Base::name << endl; + cout << "**** End of scope1 ****" << endl; + } + cout << endl << "**** Classes with virtual functions ****" << endl; + cout << "**** Construct class Base2 instance base2: 'Third'" << endl; + Base2 base2{"Third"}; + cout << "**** Call signal from base2" << endl; + base2.signal(); + { + cout << "**** Construct class Derived2 instance derived2: 'Fourth'" << endl; + Derived2 derived2{"Fourth"}; + cout << "**** Call signal() and shadowed signal()" << endl; + derived2.signal(); + derived2.Derived2::signal(); + derived2.Base2::signal(); + cout << "**** Assign &base2 to Base2* base2Ptr and call base2Ptr->signal() ****" << endl; + const Base2* base2Ptr = &base2; + base2Ptr->signal(); + cout << "**** Assign &derived2 to Base2* base2Ptr and call base2Ptr->signal() ****" << endl; + base2Ptr = &derived2; + base2Ptr->signal(); + cout << "**** Assign &derived2 to Derived2* derived2Ptr and call derived2Ptr->signal() ****" << endl; + const Derived2* derived2Ptr = &derived2; + derived2Ptr->signal(); + cout << "**** No override over namespaces" << endl; + derived2Ptr->signal2(1); + //derived2Ptr->signal2(); //error: no matching function for call to ‘Derived2::signal2() const + cout << "**** End of scope2 ****" << endl; + } + cout << "sizeof(Base): " << sizeof(Base) << endl; + cout << "sizeof(Derived): " << sizeof(Derived) << endl; + cout << "sizeof(Base2): " << sizeof(Base2) << endl; + cout << "sizeof(Derived2): " << sizeof(Derived2) << endl; + cout << "sizeof(string): " << sizeof(string) << endl; + cout << "sizeof(void*): " << sizeof(void*) << endl; + const char * p{getenv("PATH")}; + cout << "PATH=" << p << endl; + return 0; +} diff --git a/ClassMembersMultiple/.cproject b/ClassMembersMultiple/.cproject new file mode 100644 index 0000000..ffde2bf --- /dev/null +++ b/ClassMembersMultiple/.cproject @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClassMembersMultiple/.project b/ClassMembersMultiple/.project new file mode 100644 index 0000000..fd8ffa2 --- /dev/null +++ b/ClassMembersMultiple/.project @@ -0,0 +1,27 @@ + + + ClassMembersMultiple + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ClassMembersMultiple/src/ClassMembersMultiple.cpp b/ClassMembersMultiple/src/ClassMembersMultiple.cpp new file mode 100644 index 0000000..f54a4a9 --- /dev/null +++ b/ClassMembersMultiple/src/ClassMembersMultiple.cpp @@ -0,0 +1,113 @@ +//============================================================================ +// Name : ClassMembersMultiple.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Demonstrates composition of class from 2 parent classes and object sizes +//============================================================================ + +#include +using namespace std; + +class BaseA { +public: + BaseA(const string& name_) : name(name_) { cout << "BaseA(const string& name_) :" << name << endl; } + ~BaseA() { cout << "~BaseA() :" << name << endl; } + void signal() const { cout << "BaseA::signal : " << name << endl; } + const string name; +}; + +class BaseB { +public: + BaseB(const string& name_) : name(name_) { cout << "BaseB(const string& name_) : " << name_ << endl; } + ~BaseB() { cout << "~BaseB() :" << name << endl; } + void signal() const { cout << "BaseB::signal : " << name << endl; } + const string name; +}; + +class Composite : public BaseA, public BaseB { +public: + Composite(const string& name_) : BaseA(string("BaseA::").append(name_)), BaseB(string("BaseB::").append(name_)) { cout << "Composite(const string& name_) : " << name_ << endl; } + ~Composite() { cout << "~Composite() :" << endl; } + void signal() const { cout << "Composite::signal : " << BaseA::name << " " << BaseB::name << endl; } +}; + +class BaseA2 { +public: + BaseA2(const string& name_) : name(name_) { cout << "BaseA2(const string& name_) :" << name << endl; } + virtual ~BaseA2() { cout << "~BaseA2() :" << name << endl; } + virtual void signal() const { cout << "BaseA2::signal : " << name << endl; } + const string name; +}; + +class BaseB2 { +public: + BaseB2(const string& name_) : name(name_) { cout << "BaseB2(const string& name_) : " << name_ << endl; } + virtual ~BaseB2() { cout << "~BaseB2() :" << name << endl; } + virtual void signal() const { cout << "BaseB2::signal : " << name << endl; } + const string name; +}; + +class Composite2 : public BaseA2, public BaseB2 { +public: + Composite2(const string& name_) : BaseA2(string("BaseA2::").append(name_)), BaseB2(string("BaseB2::").append(name_)) { cout << "Composite2(const string& name_) : " << name_ << endl; } + virtual ~Composite2() { cout << "~Composite2() :" << endl; } + void signal() const override { cout << "Composite2::signal : " << BaseA2::name << " " << BaseB2::name << endl; } +}; + +int main() { + cout << "**** Construct class Composite instance c: 'First'" << endl; + Composite c{"First"}; + cout << "**** Call signal from c" << endl; + c.signal(); + + cout << "**** Call signal with explicit names" << endl; + c.BaseA::signal(); + c.BaseB::signal(); + c.Composite::signal(); + cout << "**** Member access" << endl; + // cout << c.name << endl; //error: request for member ‘name’ is ambiguous + // cout << c.Composite::name << endl; // error: request for member ‘name’ is ambiguous + cout << c.BaseA::name << endl; + cout << c.BaseB::name << endl; + + + cout << endl << "**** with virtual functions ****" << endl; + cout << "**** Construct class BaseA2 and BaseB2 instance av bv: 'Second'" << endl; + BaseA2 av{"Second"}; + av.signal(); + BaseB2 bv{"Third"}; + bv.signal(); + cout << "**** Construct class Composite2 instance cv: 'Fives'" << endl; + Composite2 cv{"Fives"}; + cout << "**** Call signal from cv" << endl; + cv.signal(); + cout << "**** Call signal with explicit names" << endl; + cv.BaseA2::signal(); + cv.BaseB2::signal(); + cv.Composite2::signal(); + + cout << "**** Pointer operations with base pointers BaseA2* and BaseB2*" << endl; + const BaseA2* avp = &cv; + const BaseB2* bvp = &cv; + avp->signal(); + bvp->signal(); + cout << "**** Pointer operations with Composite2*" << endl; + const Composite2* cvp{&cv}; + cvp->signal(); + cvp->Composite2::signal(); + cvp->BaseB2::signal(); + cvp->BaseA2::signal(); + + cout << "sizeof(BaseA): " << sizeof(BaseA) << endl; + cout << "sizeof(BaseB): " << sizeof(BaseB) << endl; + cout << "sizeof(Composite): " << sizeof(Composite) << endl; + cout << "sizeof(BaseA2): " << sizeof(BaseA2) << endl; + cout << "sizeof(BaseB2): " << sizeof(BaseB2) << endl; + cout << "sizeof(Composite2): " << sizeof(Composite2) << endl; + cout << "sizeof(string): " << sizeof(string) << endl; + cout << "sizeof(void*): " << sizeof(void*) << endl; + + + return 0; +} diff --git a/ClassMembersMultiple2/.cproject b/ClassMembersMultiple2/.cproject new file mode 100644 index 0000000..7840d86 --- /dev/null +++ b/ClassMembersMultiple2/.cproject @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClassMembersMultiple2/.project b/ClassMembersMultiple2/.project new file mode 100644 index 0000000..abb0bec --- /dev/null +++ b/ClassMembersMultiple2/.project @@ -0,0 +1,27 @@ + + + ClassMembersMultiple2 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ClassMembersMultiple2/src/ClassMembersMultiple2.cpp b/ClassMembersMultiple2/src/ClassMembersMultiple2.cpp new file mode 100644 index 0000000..c0312f6 --- /dev/null +++ b/ClassMembersMultiple2/src/ClassMembersMultiple2.cpp @@ -0,0 +1,125 @@ +//============================================================================ +// Name : ClassMembersMultiple2.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; + +class A { +public: + A(const string& name_) : name(string(name_).append(" A")) { cout << "A(const string& name_) :" << name << endl; } + ~A() { cout << "~A() :" << name << endl; } + void signal() const { cout << "A::signal : " << name << endl; } + const string name; +}; + +class B : public A { +public: + B(const string& name_) : A(string(name_).append(" B")) { cout << "B(const string& name_)" << endl; } + ~B() { cout << "~B()" << endl; } + void signal() const { cout << "B::signal : " << name << endl; } +}; + +class C : public A { +public: + C(const string& name_) : A(string(name_).append(" C")) { cout << "C(const string& name_)" << endl; } + ~C() { cout << "~C()" << endl; } + void signal() const { cout << "C::signal : " << name << endl; } +}; + +class D : public B, public C { +public: + D(const string& name_) : B(string(name_).append(" D")), C(string(name_).append(" D")) { cout << "D(const string& name_)" << endl; } + ~D() { cout << "~D()" << endl; } + void signal() const { cout << "D::signal : " << B::name << " " << C::name << endl; } +}; + +class AV { +public: + AV(const string& name_) : name(string(name_).append(" AV")) { cout << "AV(const string& name_) :" << name << endl; } + virtual ~AV() { cout << "~AV() :" << name << endl; } + virtual void signal() const { cout << "AV::signal : " << name << endl; } + const string name; +}; + +class BV : public AV { +public: + BV(const string& name_) : AV(string(name_).append(" BV")) { cout << "BV(const string& name_)" << endl; } + virtual ~BV() override { cout << "~BV()" << endl; } + virtual void signal() const override { cout << "BV::signal : " << name << endl; } +}; + +class CV : public AV { +public: + CV(const string& name_) : AV(string(name_).append(" CV")) { cout << "CV(const string& name_)" << endl; } + virtual ~CV() override { cout << "~CV()" << endl; } + virtual void signal() const override { cout << "CV::signal : " << name << endl; } +}; + +class DV : public BV, public CV { +public: + DV(const string& name_) : BV(string(name_).append(" DV")), CV(string(name_).append(" DV")) { cout << "DV(const string& name_)" << endl; } + virtual ~DV() override { cout << "~DV()" << endl; } + virtual void signal() const override { cout << "DV::signal : " << BV::name << " " << CV::name << endl; } +}; + + +int main() { + cout << "-- Construct class D instance d: 'Object d'" << endl; + D d{"Object d"}; + + cout << "-- Signal operations with D" << endl; + d.signal(); + d.D::signal(); + d.C::signal(); + d.B::signal(); + + cout << "-- Virtual --" << endl; + cout << "-- Construct class DV instance dv: 'Object dv'" << endl; + DV dv{"Object dv"}; + cout << "-- Signal operations with DV" << endl; + dv.signal(); + dv.DV::signal(); + dv.CV::signal(); + dv.BV::signal(); + + AV av{"Object av"}; + cout << "-- Operations with avp" << endl; + const AV* avp{&av}; + avp->signal(); + //avp = &dv; //error + + cout << "-- Operations with bvp" << endl; + const BV* bvp{&dv}; + bvp->signal(); + bvp->AV::signal(); + bvp->BV::signal(); + + cout << "-- Operations with cvp" << endl; + const CV* cvp{&dv}; + cvp->signal(); + cvp->AV::signal(); + cvp->CV::signal(); + + cout << "-- Operations with dvp" << endl; + const DV* dvp{&dv}; + dvp->signal(); + //dvp->AV::signal(); error + dvp->BV::signal(); + dvp->CV::signal(); + + cout << "sizeof(A): " << sizeof(A) << endl; + cout << "sizeof(B): " << sizeof(B) << endl; + cout << "sizeof(C): " << sizeof(C) << endl; + cout << "sizeof(D): " << sizeof(D) << endl; + cout << "sizeof(AV): " << sizeof(AV) << endl; + cout << "sizeof(BV): " << sizeof(BV) << endl; + cout << "sizeof(CV): " << sizeof(CV) << endl; + cout << "sizeof(DV): " << sizeof(DV) << endl; + + return 0; +} diff --git a/ClassMembersMultiple2Virtual/.cproject b/ClassMembersMultiple2Virtual/.cproject new file mode 100644 index 0000000..44e57fb --- /dev/null +++ b/ClassMembersMultiple2Virtual/.cproject @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClassMembersMultiple2Virtual/.project b/ClassMembersMultiple2Virtual/.project new file mode 100644 index 0000000..2dd2629 --- /dev/null +++ b/ClassMembersMultiple2Virtual/.project @@ -0,0 +1,27 @@ + + + ClassMembersMultiple2Virtual + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ClassMembersMultiple2Virtual/src/ClassMembersMultiple2Virtual.cpp b/ClassMembersMultiple2Virtual/src/ClassMembersMultiple2Virtual.cpp new file mode 100644 index 0000000..d6c4e4e --- /dev/null +++ b/ClassMembersMultiple2Virtual/src/ClassMembersMultiple2Virtual.cpp @@ -0,0 +1,125 @@ +//============================================================================ +// Name : ClassMembersMultiple2Virtual.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; + +class A { +public: + A(const string& name_) : name(string(name_).append(" A")) { cout << "A(const string& name_) :" << name << endl; } + ~A() { cout << "~A() :" << name << endl; } + void signal() const { cout << "A::signal : " << name << endl; } + const string name; +}; + +class B : virtual public A { +public: + B(const string& name_) : A(string(name_).append(" B")) { cout << "B(const string& name_)" << endl; } + ~B() { cout << "~B()" << endl; } + void signal() const { cout << "B::signal : " << name << endl; } +}; + +class C : virtual public A { +public: + C(const string& name_) : A(string(name_).append(" C")) { cout << "C(const string& name_)" << endl; } + ~C() { cout << "~C()" << endl; } + void signal() const { cout << "C::signal : " << name << endl; } +}; + +class D : public B, public C { +public: + D(const string& name_) : A(string(name_).append(" D")), B(string(name_).append(" D")), C(string(name_).append(" D")) { cout << "D(const string& name_)" << endl; } + ~D() { cout << "~D()" << endl; } + void signal() const { cout << "D::signal : " << B::name << " " << C::name << endl; } +}; + +class AV { +public: + AV(const string& name_) : name(string(name_).append(" AV")) { cout << "AV(const string& name_) :" << name << endl; } + virtual ~AV() { cout << "~AV() :" << name << endl; } + virtual void signal() const { cout << "AV::signal : " << name << endl; } + const string name; +}; + +class BV : virtual public AV { +public: + BV(const string& name_) : AV(string(name_).append(" BV")) { cout << "BV(const string& name_)" << endl; } + virtual ~BV() override { cout << "~BV()" << endl; } + virtual void signal() const override { cout << "BV::signal : " << name << endl; } +}; + +class CV : virtual public AV { +public: + CV(const string& name_) : AV(string(name_).append(" CV")) { cout << "CV(const string& name_)" << endl; } + virtual ~CV() override { cout << "~CV()" << endl; } + virtual void signal() const override { cout << "CV::signal : " << name << endl; } +}; + +class DV : public BV, public CV { +public: + DV(const string& name_) : AV(string(name_).append(" DV")), BV(string(name_).append(" DV")), CV(string(name_).append(" DV")) { cout << "DV(const string& name_)" << endl; } + virtual ~DV() override { cout << "~DV()" << endl; } + virtual void signal() const override { cout << "DV::signal : " << BV::name << " " << CV::name << endl; } +}; + + +int main() { + cout << "-- Construct class D instance d: 'Object d'" << endl; + D d{"Object d"}; + + cout << "-- Signal operations with D" << endl; + d.signal(); + d.D::signal(); + d.C::signal(); + d.B::signal(); + + cout << "-- Virtual --" << endl; + cout << "-- Construct class DV instance dv: 'Object dv'" << endl; + DV dv{"Object dv"}; + cout << "-- Signal operations with DV" << endl; + dv.signal(); + dv.DV::signal(); + dv.CV::signal(); + dv.BV::signal(); + + AV av{"Object av"}; + cout << "-- Operations with avp" << endl; + const AV* avp{&av}; + avp->signal(); + //avp = &dv; //error + + cout << "-- Operations with bvp" << endl; + const BV* bvp{&dv}; + bvp->signal(); + bvp->AV::signal(); + bvp->BV::signal(); + + cout << "-- Operations with cvp" << endl; + const CV* cvp{&dv}; + cvp->signal(); + cvp->AV::signal(); + cvp->CV::signal(); + + cout << "-- Operations with dvp" << endl; + const DV* dvp{&dv}; + dvp->signal(); + //dvp->AV::signal(); error + dvp->BV::signal(); + dvp->CV::signal(); + + cout << "sizeof(A): " << sizeof(A) << endl; + cout << "sizeof(B): " << sizeof(B) << endl; + cout << "sizeof(C): " << sizeof(C) << endl; + cout << "sizeof(D): " << sizeof(D) << endl; + cout << "sizeof(AV): " << sizeof(AV) << endl; + cout << "sizeof(BV): " << sizeof(BV) << endl; + cout << "sizeof(CV): " << sizeof(CV) << endl; + cout << "sizeof(DV): " << sizeof(DV) << endl; + + return 0; +} diff --git a/ClassMembersMultipleVirtual/.cproject b/ClassMembersMultipleVirtual/.cproject new file mode 100644 index 0000000..2f79c07 --- /dev/null +++ b/ClassMembersMultipleVirtual/.cproject @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClassMembersMultipleVirtual/.project b/ClassMembersMultipleVirtual/.project new file mode 100644 index 0000000..4a21f52 --- /dev/null +++ b/ClassMembersMultipleVirtual/.project @@ -0,0 +1,27 @@ + + + ClassMembersMultipleVirtual + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ClassMembersMultipleVirtual/src/ClassMembersMultipleVirtual.cpp b/ClassMembersMultipleVirtual/src/ClassMembersMultipleVirtual.cpp new file mode 100644 index 0000000..e62c78c --- /dev/null +++ b/ClassMembersMultipleVirtual/src/ClassMembersMultipleVirtual.cpp @@ -0,0 +1,123 @@ +//============================================================================ +// Name : ClassMembersMultipleVirtual.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ +#include +using namespace std; + +class A { +public: + A(const string& name_) : name(name_) { cout << "A(const string& name_) :" << name << endl; } + ~A() { cout << "~A() :" << name << endl; } + void signal() const { cout << "A::signal : " << name << endl; } + const string name; +}; + +class B { +public: + B(const string& name_) : name(name_) { cout << "B(const string& name_) : " << name_ << endl; } + ~B() { cout << "~B() :" << name << endl; } + void signal() const { cout << "B::signal : " << name << endl; } + const string name; +}; + +class C : virtual public A, virtual public B { +public: + C(const string& name_) : A(name_), B(name_) { cout << "C(const string& name_) : " << name_ << endl; } + ~C() { cout << "~C() :" << endl; } + void signal() const { cout << "C::signal : " << A::name << " " << B::name << endl; } +}; + +class AV { +public: + AV(const string& name_) : name(name_) { cout << "AV(const string& name_) :" << name << endl; } + virtual ~AV() { cout << "~AV() :" << name << endl; } + virtual void signal() const { cout << "AV::signal : " << name << endl; } + const string name; +}; + +class BV { +public: + BV(const string& name_) : name(name_) { cout << "BV(const string& name_) : " << name_ << endl; } + virtual ~BV() { cout << "~BV() :" << name << endl; } + virtual void signal() const { cout << "BV::signal : " << name << endl; } + const string name; +}; + +class CV : virtual public AV, virtual public BV { +public: + CV(const string& name_) : AV(name_), BV(name_) { cout << "CV(const string& name_) : " << name_ << endl; } + virtual ~CV() { cout << "~CV() :" << endl; } + virtual void signal() const override { cout << "CV::signal : " << AV::name << " " << BV::name << endl; } +}; + +int main() { + cout << "-- Construct class A instance a: 'First a'" << endl; + //A aa; -> error : No default constructor + A a{"First a"}; + cout << "-- Call signal from a" << endl; + a.signal(); + cout << "-- Construct class B instance b: 'Second b'" << endl; + B b{"Second b"}; + cout << "-- Call signal from b" << endl; + b.signal(); + cout << "-- Construct class C instance c: 'Third c'" << endl; + C c{"Third c"}; + cout << "-- Call signal from c" << endl; + c.signal(); + cout << "-- Call signal with explicit names" << endl; + c.A::signal(); + c.B::signal(); + c.C::signal(); + + cout << "-- Virtual --" << endl; + cout << "-- Construct class AV instance av: 'First av'" << endl; + AV av{"First av"}; + cout << "-- Call signal from av" << endl; + av.signal(); + cout << "-- Construct class BV instance bv: 'Second bv'" << endl; + BV bv{"Second bv"}; + cout << "-- Call signal from bv" << endl; + bv.signal(); + cout << "-- Construct class CV instance cv: 'Third cv'" << endl; + CV cv{"Third cv"}; + cout << "-- Call signal from cv" << endl; + cv.signal(); + cout << "-- Call signal with explicit names" << endl; + cv.AV::signal(); + cv.BV::signal(); + cv.CV::signal(); + + cout << "Operations with AV*" << endl; + const AV* avp = &av; + cout << "AV* avp = &av; avp->signal()" << endl; + avp->signal(); + cout << "avp = &cv; avp->signal()" << endl; + avp = &cv; + avp->signal(); + cout << "Operations with BV*" << endl; + const BV* bvp = &bv; + cout << "BV* bvp = &bv; bvp->signal()" << endl; + bvp->signal(); + cout << "bvp = &cv; vvp->signal()" << endl; + bvp = &cv; + bvp->signal(); + cout << "Operations with CV*" << endl; + const CV* cvp{&cv}; + cvp->signal(); + cvp->CV::signal(); + cvp->BV::signal(); + cvp->AV::signal(); + + cout << "sizeof(A): " << sizeof(A) << endl; + cout << "sizeof(B): " << sizeof(B) << endl; + cout << "sizeof(C): " << sizeof(C) << endl; + cout << "sizeof(AV): " << sizeof(AV) << endl; + cout << "sizeof(BV): " << sizeof(BV) << endl; + cout << "sizeof(CV): " << sizeof(CV) << endl; + + return 0; +} diff --git a/Definitions/.cproject b/Definitions/.cproject new file mode 100644 index 0000000..f78af43 --- /dev/null +++ b/Definitions/.cproject @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Definitions/.project b/Definitions/.project new file mode 100644 index 0000000..6ca75dc --- /dev/null +++ b/Definitions/.project @@ -0,0 +1,27 @@ + + + Definitions + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Definitions/.settings/org.eclipse.cdt.codan.core.prefs b/Definitions/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..44be2e5 --- /dev/null +++ b/Definitions/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,75 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.codan.checkers.errnoreturn=Warning +org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return\\")",implicit\=>false} +org.eclipse.cdt.codan.checkers.errreturnvalue=Error +org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused return value\\")"} +org.eclipse.cdt.codan.checkers.nocommentinside=-Error +org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Nesting comments\\")"} +org.eclipse.cdt.codan.checkers.nolinecomment=-Error +org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Line comments\\")"} +org.eclipse.cdt.codan.checkers.noreturn=Error +org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return value\\")",implicit\=>false} +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Abstract class cannot be instantiated\\")"} +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Ambiguous problem\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment in condition\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment to itself\\")"} +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No break at end of case\\")",no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false,enable_fallthrough_quickfix_param\=>false} +org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning +org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Catching by reference is recommended\\")",unknown\=>false,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Circular inheritance\\")"} +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class members should be properly initialized\\")",skip\=>true} +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem=Error +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid 'decltype(auto)' specifier\\")"} +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Field cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Function cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error +org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid arguments\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid template argument\\")"} +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Label statement not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Member declaration not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Method cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Name convention for function\\")",pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class has a virtual method and non-virtual destructor\\")"} +org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error +org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid overload\\")"} +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redeclaration\\")"} +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redefinition\\")"} +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=Warning +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Return with parenthesis\\")"} +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Format String Vulnerability\\")"} +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Statement has no effect\\")",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suggested parenthesis around expression\\")",paramNot\=>false} +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suspicious semicolon\\")",else\=>false,afterelse\=>false} +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Type cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused function declaration\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")} +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"} +org.eclipse.cdt.qt.core.qtproblem=Warning +org.eclipse.cdt.qt.core.qtproblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>true,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>null} diff --git a/Definitions/src/Definitions.cpp b/Definitions/src/Definitions.cpp new file mode 100644 index 0000000..87fb313 --- /dev/null +++ b/Definitions/src/Definitions.cpp @@ -0,0 +1,144 @@ +/* + * Definitions.cpp + * + * Created on: Nov 24, 2019 + * Author: joergboe + */ + +#include +#include +#include + +using namespace std; + +constexpr size_t BUFFSIZE = 1024000; + +//A class with default constructor that makes a printout +class MyClass { +public: + int i; + MyClass(): i(55) { + cout << "MyClass()" << endl; + } +}; + +//A class with default constructor which does not initialize all members +struct MyBuggyClass { + int i, j; + MyBuggyClass(): i{56} {}; +}; + +int ig; //defined value 0 + +MyClass myClassg; + +char buffg[BUFFSIZE]; //defined ? + +int main(int argc, char **argv) { + cout << "Hello Definitions" << endl; + + { + cout << "Global values are defined:" << endl; + cout << "ig=" << ig << " myClassg.i=" << myClassg.i << endl; + size_t buffzeros = 0; + for (size_t i=0; i v; + size_t count = 0; + MyBuggyClass* x; + do { + x = new MyBuggyClass; + v.push_back(x); + ++count; + } while((count < 100000) && (x->i == 56) && (x->j == 0)); + if (count < 100000) { + cout << "First uninitialized value found at count=" << count << "x->i=" << x->i << "x->j=" << x->j << endl; + } else { + cout << "No uninitialized value found" << endl; + } + for ( MyBuggyClass* i : v) + delete i; + + delete ps; + delete cp; + + cout << "End!" << endl; + return EXIT_SUCCESS; +} + diff --git a/ExceptionProject/.cproject b/ExceptionProject/.cproject new file mode 100644 index 0000000..61ebc9c --- /dev/null +++ b/ExceptionProject/.cproject @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExceptionProject/.project b/ExceptionProject/.project new file mode 100644 index 0000000..28d41bd --- /dev/null +++ b/ExceptionProject/.project @@ -0,0 +1,27 @@ + + + ExceptionProject + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/ExceptionProject/src/ExceptionProject.cpp b/ExceptionProject/src/ExceptionProject.cpp new file mode 100644 index 0000000..6455bd2 --- /dev/null +++ b/ExceptionProject/src/ExceptionProject.cpp @@ -0,0 +1,82 @@ +//============================================================================ +// Name : ExceptionProject.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +#include +#include + +void myfunc(int inp) { + std::cout << "myfunc(" << inp << ")" << std::endl; + switch (inp) { + case 0: + std::cout << "throw std lib error type a sibling from std::exception" << std::endl; + throw std::invalid_argument("Reason given"); + case 1: + std::cout << "throw std::exception" << std::endl; + throw std::exception(); + case 2: + std::cout << "throw exception pointer with std lib error type a sibling from std::exception" << std::endl; + throw new std::invalid_argument("Reason given 2"); + case 3: { + std::cout << "throw a void pointer" << std::endl; + void *ptr = new std::invalid_argument("Reason given 3"); + throw ptr; + } + case 4: { + std::cout << "throw an int" << std::endl; + int e = 4; + throw e; + } + case 5: { + std::cout << "throw any other (std::string)" << std::endl; + throw std::string("do not see this"); + } + }; +} + +int main() { + std::cout << "ExceptionProject START" << std::endl; + + for (int i=0; i<6; i++) { + try { + myfunc(i); + } catch (const std::exception& e) { + std::cout << "Catch instance of std::exception& e.what(): " << e.what() << std::endl; + } catch (const std::exception * e) { + std::cout << "Catch instance of std::exception* e->what(): " << e->what() << std::endl; + delete e; + } catch (const void* e) { + std::cout << "Catch instance of void*" << std::endl; + //delete e; //problem! + } catch (const int e) { + std::cout << "Catch instance of int: " << e << std::endl; + } catch (...) { + std::cout << "catch(..)" << std::endl; + } + std::cout << std::endl; + } + + try { + myfunc(0); //throw a sibling from std::exception + } catch (std::exception e) { + std::cout << "Catch instance of std::exception e.what(): " << e.what() << std::endl; + std::cout << "This is not recommended because e is not polymorph" << std::endl; + } + std::cout << std::endl; + + try { + myfunc(4); + } catch (const int& e) { + std::cout << "Catch instance of int&: " << e << std::endl; + std::cout << "This is possible" << std::endl; + } + std::cout << std::endl; + + std::cout << "ExceptionProject END" << std::endl; + return 0; +} diff --git a/FunctionPointers/.cproject b/FunctionPointers/.cproject new file mode 100644 index 0000000..2e31efa --- /dev/null +++ b/FunctionPointers/.cproject @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FunctionPointers/.project b/FunctionPointers/.project new file mode 100644 index 0000000..1f15c86 --- /dev/null +++ b/FunctionPointers/.project @@ -0,0 +1,27 @@ + + + FunctionPointers + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/FunctionPointers/.settings/org.eclipse.cdt.codan.core.prefs b/FunctionPointers/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..daca6f7 --- /dev/null +++ b/FunctionPointers/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,75 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.codan.checkers.errnoreturn=Warning +org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return\\")",implicit\=>false} +org.eclipse.cdt.codan.checkers.errreturnvalue=Error +org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused return value\\")"} +org.eclipse.cdt.codan.checkers.nocommentinside=-Error +org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Nesting comments\\")"} +org.eclipse.cdt.codan.checkers.nolinecomment=-Error +org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Line comments\\")"} +org.eclipse.cdt.codan.checkers.noreturn=Error +org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return value\\")",implicit\=>false} +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Abstract class cannot be instantiated\\")"} +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Ambiguous problem\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment in condition\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment to itself\\")"} +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No break at end of case\\")",no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false,enable_fallthrough_quickfix_param\=>false} +org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning +org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Catching by reference is recommended\\")",unknown\=>false,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Circular inheritance\\")"} +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class members should be properly initialized\\")",skip\=>true} +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem=Error +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid 'decltype(auto)' specifier\\")"} +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Field cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Function cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error +org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid arguments\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid template argument\\")"} +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Label statement not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Member declaration not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Method cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Name convention for function\\")",pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class has a virtual method and non-virtual destructor\\")"} +org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error +org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid overload\\")"} +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redeclaration\\")"} +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redefinition\\")"} +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=Warning +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Return with parenthesis\\")"} +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=Warning +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Format String Vulnerability\\")"} +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Statement has no effect\\")",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suggested parenthesis around expression\\")",paramNot\=>false} +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suspicious semicolon\\")",else\=>false,afterelse\=>false} +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Type cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused function declaration\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")} +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"} +org.eclipse.cdt.qt.core.qtproblem=Warning +org.eclipse.cdt.qt.core.qtproblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>true,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>null} diff --git a/FunctionPointers/src/FunctionPointers.cpp b/FunctionPointers/src/FunctionPointers.cpp new file mode 100644 index 0000000..e7a1172 --- /dev/null +++ b/FunctionPointers/src/FunctionPointers.cpp @@ -0,0 +1,125 @@ +//============================================================================ +// Name : FunctionPointers.cpp +// Author : joergboe +//============================================================================ + +#include +#include +#include + +using namespace std; + +int f1(int inp); +int f1ne(int inp) noexcept; +int * f2(int inp); +int const * f3(int inp); +int & f4(int inp); +int const & f5(int inp); + +int resf2, resf3, resf4, resf5; + + +int main() { + cout << "Hello FunctionPointers" << endl; + cout << "define a function pointer to a function and use it\n"; + int (* fp1)(int) = &f1; + int res = (*fp1)(4); + cout << "(*fp1)(4) = " << res << endl; + cout << "The & to obtain the address of the function is optional and the * to the execute function is optional\n"; + fp1 = f1; + cout << "fp1(4) = " << fp1(4) << endl; + cout << "The function assigned to the pointer must have the same number and type of parameters and return type\n"; + cout << "noexcept specification is part of the function type. A normal pointer may point to a noexcept funtion\n"; + int (* fp1ne)(int) noexcept = &f1ne; + res = (*fp1ne)(4); + cout << "res=" << res << endl; + cout << "A noexcept pointer must not point to a normal function (which may throw an execpion)\n"; + fp1ne = &f1; + cout << "This may be a problem with (GCC) 4.8.5\n"; + res = (*fp1ne)(4); + cout << "res=" << res << endl; + + //fp1 = &f2; //error: invalid conversion from ‘int* (*)(int)’ to ‘int (*)(int)’ [-fpermissive] + //fp1 = &f3; //dito error + //fp1 = &f4; //dito error + //fp1 = &f5; //dito error + + cout << "Define and use a constant function pointer\n"; + int (* const fp2)(int) = &f1; + res = (*fp2)(5); + cout << "res=" << res << endl; + //fp2 = &f1; //error: assignment of read-only variable ‘fp2’ + + cout << "Define and use a constant function pointer with return type pointer to constant value\n"; + int const * (* const fp3const)(int) = &f3; + int const * const res3px = (*fp3const)(4); + cout << "*res3px=" << *res3px << endl; + + cout << "Define and use a constant function pointer with return type constant reference and use type alias\n"; + int const & (*fp5)(int inp) = &f5; + cout << "resfp5=" << (*fp5)(4) << endl; + + cout << "Use type alias for function pointer old stype\n"; + typedef int (*Palias1)(int); + Palias1 pa1 = &f1; + cout << "(*pa1)(2)=" << (*pa1)(2) << endl; + + cout << "Use type alias for function type old stype and use it as pointer\n"; + typedef int Alias1(int); + Alias1 * pa2 = &f1; + cout << "(*pa2)(2)=" << (*pa2)(2) << endl; + + cout << "Use type alias for function pointer new stype\n"; + using Palias2 = int(*)(int); + Palias2 pa3 = f1; + cout << "pa3(3)=" << pa3(3) << endl; + + cout << "Use type alias for function type and use it as pointer new stype\n"; + using Alias2 = int (int); + Alias2 * pa4 = f1; + cout << "pa4(3)=" << pa4(3) << endl; + + cout << "Exception specification should not be part of the alias. Problem with (GCC) 4.8.5\n"; + using Alias3 = int(*)(int) noexcept; + cout << "This assignement shjould not be possible. Problem with (GCC) 4.8.5\n"; + Alias3 pa5 = &f1; + cout << "(*pa5)(3)=" << (*pa5)(3) << endl; + + cout << "typeinfo fp1 : " << typeid(fp1).name() << endl; + cout << "typeinfo fp1ne : " << typeid(fp1ne).name() << endl; + cout << "typeinfo fp2 : " << typeid(fp2).name() << endl; + cout << "typeinfo fp3const: " << typeid(fp3const).name() << endl; + cout << "typeinfo fp5 : " << typeid(fp5).name() << endl; + cout << "typeinfo Palias1 : " << typeid(Palias1).name() << endl; + cout << "typeinfo Palias2 : " << typeid(Palias2).name() << endl; + cout << "typeinfo Alias1 : " << typeid(Alias1).name() << endl; + cout << "typeinfo Alias2 : " << typeid(Alias2).name() << endl; + + cout << "END" << endl; + return 0; +} + +int f1(int inp) { + int res = inp + inp + 1; + if (res > 15) throw exception(); + return res; +} +int f1ne(int inp) noexcept { + return inp + inp + 1; +} +int * f2(int inp) { + resf2 = inp + inp + 2; + return &resf2; +} +int const * f3(int inp) { + resf3 = inp + inp + 3; + return &resf3; +} +int & f4(int inp) { + resf4 = inp + inp + 4; + return resf4; +} +int const & f5(int inp) { + resf5 = inp + inp + 5; + return resf5; +} diff --git a/FunctionTemplate/.cproject b/FunctionTemplate/.cproject new file mode 100644 index 0000000..3683f3e --- /dev/null +++ b/FunctionTemplate/.cproject @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FunctionTemplate/.project b/FunctionTemplate/.project new file mode 100644 index 0000000..c945a5b --- /dev/null +++ b/FunctionTemplate/.project @@ -0,0 +1,27 @@ + + + FunctionTemplate + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/FunctionTemplate/src/FunctionTemplate.cpp b/FunctionTemplate/src/FunctionTemplate.cpp new file mode 100644 index 0000000..4b346b5 --- /dev/null +++ b/FunctionTemplate/src/FunctionTemplate.cpp @@ -0,0 +1,67 @@ +//============================================================================ +// Name : FunctionTemplate.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; + +template +void print(T inp) { + cout << "T:" << inp << endl; +} +template<> +void print(int inp) { + cout << "int:" << inp << endl; +} + +enum typf {none, one, two}; + +template +void print1() { + cout << "I=" << I << endl; +} +template<> +void print1<0>() { + cout << "special I=0" << endl; +} + +template +void print2(T inp, C inp2) { + cout << "CT " << ":" << inp << " " << inp2 << endl; +} +template<> +void print2(char inp, int inp2) { + cout << "special char int " << inp << endl; +} + +char Label1[] = "Label1"; //must not be constant, because wee need external binding +char Label2[] = "Label2"; + +template +void foo() { + cout << "Foo allg cp=" << cp << endl; +} +template<> +void foo() { + cout << "Special foo " << Label2 << endl; +} + +int main() { + cout << "!!!Hello World!!!" << endl; + int i = 55; + print(i); + print(5.5); + print2(i, 'a'); + print2(6.6, 1); + print2('c', 11); + print1(); + print1<0>(); + foo(); + foo(); + cout << "END" << endl; + return 0; +} diff --git a/Lambdas/.cproject b/Lambdas/.cproject new file mode 100644 index 0000000..555e6bb --- /dev/null +++ b/Lambdas/.cproject @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lambdas/.project b/Lambdas/.project new file mode 100644 index 0000000..6e084af --- /dev/null +++ b/Lambdas/.project @@ -0,0 +1,27 @@ + + + Lambdas + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Lambdas/.settings/org.eclipse.cdt.core.prefs b/Lambdas/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 0000000..6536eb6 --- /dev/null +++ b/Lambdas/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +environment/project/cdt.managedbuild.config.gnu.exe.release.315954863/append=true +environment/project/cdt.managedbuild.config.gnu.exe.release.315954863/appendContributed=true diff --git a/Lambdas/src/Lambdas.cpp b/Lambdas/src/Lambdas.cpp new file mode 100644 index 0000000..b04187a --- /dev/null +++ b/Lambdas/src/Lambdas.cpp @@ -0,0 +1,58 @@ +//============================================================================ +// Name : Lambdas.cpp +// Author : joergboe +//============================================================================ + +#include +#include +#include + +using namespace std; + +int main() { + cout << "!!!Hello Lambdas!!!" << endl; + + cout << "Labda expression components:\n" + " * Capture list: []\n" + " * Argument list (optional): ()\n" + " * specifiers (optional): mutable noexept\n" + " * Return type declaration (optional): -> Type\n" + " * Body: {}\n"; + string s1 = "String 1"; + const string s2 = "String 2 const"; + int counter = 0; + + auto l1 = [] (int x) { cout << "l1(" << x << ")\n"; }; + l1(1); + + auto l2 = [&counter] (int x) -> int {cout << "l2(" << x << ") counter=" << counter << endl; ++counter; return x + x; }; + cout << "l2(2)=" << l2(2) << endl; + + auto l3 = [&s2, &counter] (int x) -> int {cout << "l3(" << x << ") counter=" << counter << " s2= " << s2 << endl; ++counter; return x + x; }; + cout << "l3(3)=" << l3(3) << endl; + + cout << "no such thing is possible in capture list const&s2\n"; + cout << "weird error messages if an reference to a const value is in capture list ant attempt to change\n"; + //auto l4 = [&2, &counter] (int x) -> int {s2 = string("bla"); cout << "l4(" << x << ") counter=" << counter << " s2= " << s2 << endl; ++counter; return x + x; }; + //error: no match for ‘operator=’ (operand types are ‘const string {aka const std::basic_string}’ and ‘std::string {aka std::basic_string}’) + + cout << "You can change mutable values in captured content\n"; + auto l5 = [s1, &counter] (int x) mutable -> int {s1.append(" has changed"); cout << "l5(" << x << ") counter=" << counter << " s1= " << s1 << endl; ++counter; return x + x; }; + cout << "l5(5)=" << l5(5) << "s1 is still the old value=" << s1 << endl; + + cout << "But you cannot change const values in captured content\n"; + //auto l6 = [s2, &counter] (int x) mutable -> int {s2.append(" has changed"); cout << "l5(" << x << ") counter=" << counter << " s2= " << s2 << endl; ++counter; return x + x; }; + cout << "error: no matching function for call to ‘std::basic_string::append(const char [13]) const\n"; + + cout << "typeid l1 : " << typeid(l1).name() << endl; + cout << "typeid l2 : " << typeid(l2).name() << endl; + + cout << "Assignement to function pointer possible if nothing is in capture list" << endl; + auto lfp1 = [] (int x) -> double { int res = x + x; return double(res); }; + double (*fp1)(int) = lfp1; + cout << "(*fp1)(4)=" << (*fp1)(4) << endl; + cout << "typeid fp1 : " << typeid(fp1).name() << " typeid lfp1 : " << typeid(lfp1).name() << endl; + + cout << "END!" << endl; + return 0; +} diff --git a/NewDelete/.cproject b/NewDelete/.cproject new file mode 100644 index 0000000..f1a51d4 --- /dev/null +++ b/NewDelete/.cproject @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NewDelete/.project b/NewDelete/.project new file mode 100644 index 0000000..a5f20c7 --- /dev/null +++ b/NewDelete/.project @@ -0,0 +1,27 @@ + + + NewDelete + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/NewDelete/src/NewDelete.cpp b/NewDelete/src/NewDelete.cpp new file mode 100644 index 0000000..32cf2d1 --- /dev/null +++ b/NewDelete/src/NewDelete.cpp @@ -0,0 +1,33 @@ +//============================================================================ +// Name : NewDelete.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; + +int main() { + cout << "Hello NewDelete" << endl; + int * ip = new int; + *ip = 55; + cout << "ip=" << ip << " *ip=" << *ip << endl; + delete ip; + cout << "ip=" << ip << " *ip=" << *ip << endl; + ip = nullptr; + cout << "ip=" << ip << endl; + + for (int x=0; x<4; ++x) { + int * ipa = new int[x]; + cout << "Arr[" << x << "] "; + int * ipc = ipa; + for (int z=0; z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PointerToMember/.project b/PointerToMember/.project new file mode 100644 index 0000000..2687147 --- /dev/null +++ b/PointerToMember/.project @@ -0,0 +1,27 @@ + + + PointerToMember + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/PointerToMember/src/PointerToMember.cpp b/PointerToMember/src/PointerToMember.cpp new file mode 100644 index 0000000..e362686 --- /dev/null +++ b/PointerToMember/src/PointerToMember.cpp @@ -0,0 +1,69 @@ +//============================================================================ +// Name : PointerToMember.cpp +// Author : joergboe +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; + +class Base { +public: + char a; + char b; + + Base(char a_, char b_) : a(a_), b(b_) {}; + void print1(int val) { + cout << "print1 a=" << a << " b=" << b << " val=" << val << endl; + } + void print2(int val) { + cout << "print2 a=" << a << " b=" << b << " val=" << val << endl; + } +}; + +class Derived : public Base { +public: + char c; + Derived(int a_, int b_) : Base(a_, b_), c('@') {}; + void print3(int val) { + cout << "print3 a=" << a << " b=" << b << " c=" << c << " val=" << val << endl; + } +}; + +typedef char Base::* MemberPointer; +//using MemberPointer = char Base::*; //c11 stype +typedef void (Base::*MethodPointer)(int); +//using MethodPointer = void (Base::*)(int); + +int main() { + cout << "!!!Hello World!!!" << endl; + Base object1('a', 'b'); + object1.print1(55); + object1.print2(56); + + //Member Pointer + char Base::* const memberPointer1 = &Base::a; //direct declaration (const) + object1.*memberPointer1 = 'A'; + MemberPointer memberPointer2 = &Base::b; + object1.*memberPointer2 = 'B'; //declaration using alias (typedef / using + //Method Pointer + void (Base::*methodPointer1)(int) = &Base::print1; //direct declaration + Base* objectPtr = &object1; + (objectPtr->*methodPointer1)(11); + MethodPointer methodPointer2 = &Base::print2; + (object1.*methodPointer2)(22); + + //Derived + Derived object2('x','y'); + void (Derived::* methodPointer3)(int) = &Derived::print3; + (object2.*methodPointer3)(22); + methodPointer3 = &Derived::print1; + (object2.*methodPointer3)(100); + (object2.*methodPointer1)(0); //use method pointer of Base with object type Derived + + cout << "sizeof(object1)=" << sizeof(object1) << endl; + cout << "sizeof(object2)=" << sizeof(object2) << endl; + return 0; +} diff --git a/PointersAndConst/.cproject b/PointersAndConst/.cproject new file mode 100644 index 0000000..16d5dd7 --- /dev/null +++ b/PointersAndConst/.cproject @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PointersAndConst/.project b/PointersAndConst/.project new file mode 100644 index 0000000..c4cde15 --- /dev/null +++ b/PointersAndConst/.project @@ -0,0 +1,27 @@ + + + PointersAndConst + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/PointersAndConst/src/PointersAndConst.cpp b/PointersAndConst/src/PointersAndConst.cpp new file mode 100644 index 0000000..39239ae --- /dev/null +++ b/PointersAndConst/src/PointersAndConst.cpp @@ -0,0 +1,103 @@ +//============================================================================ +// Name : Pointers.cpp +// Author : joergboe +//============================================================================ + +#include +using namespace std; + +int main() { + cout << "Pointer and constant demo" << endl; + int i = 11; + int inew = 155; + cout << "declaration of an constant variable may be done with prefix or suffix const qualifier\n"; + const int ci = 55; + //ci = 100; //error: assignment of read-only variable ‘ci’ + int const ci2 = 66; + //ci2 = 100; //error: assignment of read-only variable ‘ci2’ + cout << "i=" << i << " ci=" << ci << " ci2=" << ci2 << endl; + cout << "------------------------------------------------------" << endl; + { + cout << "Pointer to mutable variable: use int * name" << endl; + int * ip = &i; + //ip = &ci; //error: invalid conversion from ‘const int*’ to ‘int*’ [-fpermissive] + //ip = &ci2; //error: invalid conversion from ‘const int*’ to ‘int*’ [-fpermissive] + cout << "Pointer to constant variable: use const int * name or int const * name" << endl; + const int * cip = &ci; + int const * cip2 = &ci2; + cout << "*ip=" << *ip << " *cip=" << *cip << " *cip2=" << *cip2 << endl; + cout << "Changes of then variable is allowed with ip only\n"; + cout << "The compiler prevents changes of constant variables\n"; + (*ip)++; + //(*cip)++; //error: increment of read-only location ‘* cip’ + //*cip2 = 166; //error: assignment of read-only location ‘* cip2’ + cout << "*ip=" << *ip << " *cip=" << *cip << " *cip2=" << *cip2 << endl; + cout << "Pointers to variable or const variable are mutable\n"; + ip = &inew; + cip = &ci2; + cip2 = &ci; + cout << "*ip=" << *ip << " *cip=" << *cip << " *cip2=" << *cip2 << endl; + cout << "Declare a pointer to a pointer with int * * ipp = &ip\n"; + int * * ipp = &ip; + cout << "**ipp=" << **ipp << "\nChange the value\n"; + ++(**ipp); + cout << "**ipp=" << **ipp << endl; + cout << "Declare a pointer to a pointer to a const variable with int const * * ipp = &cip\n"; + int const * * cipp = &cip; + cout << "**cipp=" << **cipp << " And the value can not be changed" << endl; + //++(**cipp); //error: increment of read-only location ‘* * cipp’ + } + cout << "------------------------------------------------------\n" << endl; + { + cout << "Constant Pointers are constant but the the variable may not" << endl; + cout << "A constant pointer to a mutable value. Use: int * name\n"; + int * const ipc = &i; + cout << "A constant pointer to a constant variable. Use: const int * const name or int const * const name\n"; + const int * const cipc = &ci; + int const * const cipc2 = &ci2; + cout << "*ipc=" << *ipc << " *cipc=" << *cipc << " *cipc2=" << *cipc2 << endl; + cout << "The value where a const pointer points to is mutable\n"; + (*ipc)++; + cout << "The value where pointer to const value points to are immutable\n"; + //(*cipc)++; //error: increment of read-only location ‘*(const int*)cipc’ + //(*cipc2)++; //error: increment of read-only location ‘*(const int*)cipc2’ + cout << "Const pointer are immutable\n"; + //ipc = &inew; //error: assignment of read-only variable ‘ipc’ + //cipc = &ci2; //error: assignment of read-only variable ‘cipc’ + //cipc2 = &ci; //error: assignment of read-only variable ‘cipc2’ + cout << "*ipc=" << *ipc << " *cipc=" << *cipc << " *cipc2=" << *cipc2 << endl; + } + cout << "------------------------------------------------------\n" << endl; + { + cout << "References and constant references" << endl; + int & ir = i; + const int & cir = ci; + int const & cir2 = ci2; + cout << "The value of a reference is mutable; The value of constant reference is immutable\n"; + ir++; + //cir++; //error: increment of read-only reference ‘cir’ + //cir2++; //error: increment of read-only reference ‘cir2’ + cout << "ir=" << ir << " cir=" << cir << " cir2=" << cir2 << endl; + cout << "The const reference of a mutable variable can not be used to change the value of the variable\n"; + int const & cmi = i; + //cmi++; //error: increment of read-only reference + cout << "cmi=" << cmi << endl; + cout << "The assignment to an reference is always an assignment to the variable.\n"; + //cir = ci; //error: assignment of read-only reference ‘cir’ + cout << "You can not change the address where the reference points to. The assignment is always a change of the variable\n"; + int newI = -11; + ir = newI; + cout << "newI=" << newI << " ir=" << ir << " i=" << i << endl; + const int & cirr = ci; + int const & cirr2 = ci2; + cout << "ir=" << ir << " cirr=" << cirr << " cirr2=" << cirr2 << endl; + cout << "A reference is alway const. There is no such thing like int & const cirrr = i;"; + //int & const cirrr = i; //error: ‘const’ qualifiers cannot be applied to ‘int&’ + cout << "There is no such thing like a reference to a reference int & & ...\n"; + //int & & irr = ir; //error: cannot declare reference to ‘int&’ + cout << " && is since c++11 a r-value reference." << endl; + } + cout << "Eigentlich ist das const nachgestellt systematischer" << endl; + cout << "END" << endl; + return 0; +}