-
Notifications
You must be signed in to change notification settings - Fork 0
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
joergboe
committed
Sep 3, 2020
1 parent
3fa337b
commit d723f44
Showing
42 changed files
with
3,183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> | ||
<storageModule moduleId="org.eclipse.cdt.core.settings"> | ||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1246687794"> | ||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1246687794" moduleId="org.eclipse.cdt.core.settings" name="Debug"> | ||
<externalSettings/> | ||
<extensions> | ||
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/> | ||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
</extensions> | ||
</storageModule> | ||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> | ||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.config.gnu.exe.debug.1246687794" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=unix:///var/run/docker.sock" parent="cdt.managedbuild.config.gnu.exe.debug"> | ||
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1246687794." name="/" resourcePath=""> | ||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1951468942" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug"> | ||
<targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.exe.debug.530786569" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/> | ||
<builder buildPath="${workspace_loc:/ClassMembers}/Debug" enableAutoBuild="false" id="cdt.managedbuild.target.gnu.builder.exe.debug.159314786" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/> | ||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1464724470" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> | ||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.630052717" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug"> | ||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.463205406" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/> | ||
<option defaultValue="gnu.cpp.compiler.debugging.level.max" id="gnu.cpp.compiler.exe.debug.option.debugging.level.527879627" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/> | ||
<option id="gnu.cpp.compiler.option.dialect.std.1786910136" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/> | ||
<option id="gnu.cpp.compiler.option.other.verbose.1110939300" name="Verbose (-v)" superClass="gnu.cpp.compiler.option.other.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/> | ||
<option id="gnu.cpp.compiler.option.warnings.extrawarn.2014056022" name="Extra warnings (-Wextra)" superClass="gnu.cpp.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="true" valueType="boolean"/> | ||
<option id="gnu.cpp.compiler.option.warnings.wconversion.486069010" name="Implicit conversion warnings (-Wconversion)" superClass="gnu.cpp.compiler.option.warnings.wconversion" useByScannerDiscovery="false" value="true" valueType="boolean"/> | ||
<option id="gnu.cpp.compiler.option.warnings.pedantic.2136065363" name="Pedantic (-pedantic)" superClass="gnu.cpp.compiler.option.warnings.pedantic" useByScannerDiscovery="false" value="true" valueType="boolean"/> | ||
<option id="gnu.cpp.compiler.option.other.other.1394996408" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" useByScannerDiscovery="false" value="-c -fmessage-length=0" valueType="string"/> | ||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.272315046" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1011400639" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug"> | ||
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.1773812034" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/> | ||
<option defaultValue="gnu.c.debugging.level.max" id="gnu.c.compiler.exe.debug.option.debugging.level.229198780" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/> | ||
<option id="gnu.c.compiler.option.warnings.extrawarn.1787936946" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="false" valueType="boolean"/> | ||
<option id="gnu.c.compiler.option.warnings.wconversion.814807518" name="Implicit conversion warnings (-Wconversion)" superClass="gnu.c.compiler.option.warnings.wconversion" useByScannerDiscovery="false" value="false" valueType="boolean"/> | ||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.158279113" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.20850421" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/> | ||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.1214592246" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug"> | ||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1721816986" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> | ||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> | ||
<additionalInput kind="additionalinput" paths="$(LIBS)"/> | ||
</inputType> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.669307266" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug"> | ||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1592649622" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> | ||
</tool> | ||
</toolChain> | ||
</folderInfo> | ||
<sourceEntries> | ||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/> | ||
</sourceEntries> | ||
</configuration> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> | ||
</cconfiguration> | ||
</storageModule> | ||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> | ||
<project id="ClassMembers.cdt.managedbuild.target.gnu.exe.216748465" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/> | ||
</storageModule> | ||
<storageModule moduleId="scannerConfiguration"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1246687794;cdt.managedbuild.config.gnu.exe.debug.1246687794.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.630052717;cdt.managedbuild.tool.gnu.cpp.compiler.input.272315046"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1428263760;cdt.managedbuild.config.gnu.exe.release.1428263760.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1933953841;cdt.managedbuild.tool.gnu.cpp.compiler.input.1850067992"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1428263760;cdt.managedbuild.config.gnu.exe.release.1428263760.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.1864756814;cdt.managedbuild.tool.gnu.c.compiler.input.265276617"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1246687794;cdt.managedbuild.config.gnu.exe.debug.1246687794.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1011400639;cdt.managedbuild.tool.gnu.c.compiler.input.158279113"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> | ||
<storageModule moduleId="refreshScope" versionNumber="2"> | ||
<configuration configurationName="Debug"> | ||
<resource resourceType="PROJECT" workspacePath="/ClassMembers"/> | ||
</configuration> | ||
<configuration configurationName="Release"> | ||
<resource resourceType="PROJECT" workspacePath="/ClassMembers"/> | ||
</configuration> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> | ||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> | ||
</cproject> |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ClassMembers</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> | ||
<triggers>clean,full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> | ||
<triggers>full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.cdt.core.cnature</nature> | ||
<nature>org.eclipse.cdt.core.ccnature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> | ||
</natures> | ||
</projectDescription> |
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 |
---|---|---|
@@ -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 <iostream> | ||
#include <string> | ||
#include <cstdlib> | ||
|
||
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; | ||
} |
Oops, something went wrong.