Skip to content

Commit abaa92c

Browse files
committed
Initial code commit
1 parent 3b8be56 commit abaa92c

16 files changed

+382
-0
lines changed

AssemblyInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "pch.h"
2+
3+
using namespace System;
4+
using namespace System::Reflection;
5+
using namespace System::Runtime::CompilerServices;
6+
using namespace System::Runtime::InteropServices;
7+
using namespace System::Security::Permissions;
8+
9+
[assembly:AssemblyTitleAttribute(L"CppGenericsExample")];
10+
[assembly:AssemblyDescriptionAttribute(L"")];
11+
[assembly:AssemblyConfigurationAttribute(L"")];
12+
[assembly:AssemblyCompanyAttribute(L"")];
13+
[assembly:AssemblyProductAttribute(L"CppGenericsExample")];
14+
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2019")];
15+
[assembly:AssemblyTrademarkAttribute(L"")];
16+
[assembly:AssemblyCultureAttribute(L"")];
17+
18+
[assembly:AssemblyVersionAttribute("1.0.*")];
19+
20+
[assembly:ComVisible(false)];
21+
22+
[assembly:CLSCompliantAttribute(true)];

ClassTemplate.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
#include "IGeneric.h"
3+
4+
template <class T>
5+
public ref class ClassTemplate : public IGeneric<T>
6+
{
7+
public:
8+
virtual T ReturnResult()
9+
{
10+
return 1 + 3;
11+
}
12+
};

CppGenericsExample.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "pch.h"
2+
#include "UInt64Class.h"
3+
#include "UInt32Class.h"
4+
#include "UInt16Class.h"
5+
#include "UInt8Class.h"
6+
7+
using namespace System;
8+
9+
void Print(Object^ object)
10+
{
11+
Type^ type = object->GetType();
12+
13+
Console::Write(type);
14+
Console::Write(" = ");
15+
Console::WriteLine(object);
16+
}
17+
18+
int main(array<System::String ^> ^args)
19+
{
20+
Print((gcnew UInt64Class())->ReturnResult());
21+
Print((gcnew UInt32Class())->ReturnResult());
22+
Print((gcnew UInt16Class())->ReturnResult());
23+
Print((gcnew UInt8Class())->ReturnResult());
24+
25+
return 0;
26+
}

CppGenericsExample.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28922.388
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppGenericsExample", "CppGenericsExample.vcxproj", "{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Debug|x64.ActiveCfg = Debug|x64
17+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Debug|x64.Build.0 = Debug|x64
18+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Debug|x86.ActiveCfg = Debug|Win32
19+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Debug|x86.Build.0 = Debug|Win32
20+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Release|x64.ActiveCfg = Release|x64
21+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Release|x64.Build.0 = Release|x64
22+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Release|x86.ActiveCfg = Release|Win32
23+
{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {EDB14AB2-8C88-4D33-AD48-21C149166714}
30+
EndGlobalSection
31+
EndGlobal

CppGenericsExample.vcxproj

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<ProjectGuid>{3725ABB7-5ACB-4424-A324-D0EA06C95E9C}</ProjectGuid>
24+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
25+
<Keyword>ManagedCProj</Keyword>
26+
<RootNamespace>CppGenericsExample</RootNamespace>
27+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
<ConfigurationType>Application</ConfigurationType>
32+
<UseDebugLibraries>true</UseDebugLibraries>
33+
<PlatformToolset>v142</PlatformToolset>
34+
<CLRSupport>true</CLRSupport>
35+
<CharacterSet>Unicode</CharacterSet>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<PlatformToolset>v142</PlatformToolset>
41+
<CLRSupport>true</CLRSupport>
42+
<CharacterSet>Unicode</CharacterSet>
43+
</PropertyGroup>
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
45+
<ConfigurationType>Application</ConfigurationType>
46+
<UseDebugLibraries>true</UseDebugLibraries>
47+
<PlatformToolset>v142</PlatformToolset>
48+
<CLRSupport>true</CLRSupport>
49+
<CharacterSet>Unicode</CharacterSet>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
52+
<ConfigurationType>Application</ConfigurationType>
53+
<UseDebugLibraries>false</UseDebugLibraries>
54+
<PlatformToolset>v142</PlatformToolset>
55+
<CLRSupport>true</CLRSupport>
56+
<CharacterSet>Unicode</CharacterSet>
57+
</PropertyGroup>
58+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
59+
<ImportGroup Label="ExtensionSettings">
60+
</ImportGroup>
61+
<ImportGroup Label="Shared">
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
</ImportGroup>
75+
<PropertyGroup Label="UserMacros" />
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77+
<LinkIncremental>true</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80+
<LinkIncremental>true</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
86+
<LinkIncremental>false</LinkIncremental>
87+
</PropertyGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
89+
<ClCompile>
90+
<PrecompiledHeader>Use</PrecompiledHeader>
91+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
92+
<WarningLevel>Level3</WarningLevel>
93+
<Optimization>Disabled</Optimization>
94+
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
95+
</ClCompile>
96+
<Link>
97+
<AdditionalDependencies />
98+
<SubSystem>Console</SubSystem>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<PrecompiledHeader>Use</PrecompiledHeader>
104+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
105+
<WarningLevel>Level3</WarningLevel>
106+
<Optimization>Disabled</Optimization>
107+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108+
</ClCompile>
109+
<Link>
110+
<AdditionalDependencies />
111+
<SubSystem>Console</SubSystem>
112+
</Link>
113+
</ItemDefinitionGroup>
114+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
115+
<ClCompile>
116+
<PrecompiledHeader>Use</PrecompiledHeader>
117+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
</ClCompile>
121+
<Link>
122+
<AdditionalDependencies />
123+
<SubSystem>Console</SubSystem>
124+
</Link>
125+
</ItemDefinitionGroup>
126+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
127+
<ClCompile>
128+
<PrecompiledHeader>Use</PrecompiledHeader>
129+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
130+
<WarningLevel>Level3</WarningLevel>
131+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
</ClCompile>
133+
<Link>
134+
<AdditionalDependencies />
135+
<SubSystem>Console</SubSystem>
136+
</Link>
137+
</ItemDefinitionGroup>
138+
<ItemGroup>
139+
<ResourceCompile Include="app.rc" />
140+
</ItemGroup>
141+
<ItemGroup>
142+
<ClInclude Include="ClassTemplate.h" />
143+
<ClInclude Include="IGeneric.h" />
144+
<ClInclude Include="pch.h" />
145+
<ClInclude Include="Resource.h" />
146+
<ClInclude Include="UInt16Class.h" />
147+
<ClInclude Include="UInt32Class.h" />
148+
<ClInclude Include="UInt64Class.h" />
149+
<ClInclude Include="UInt8Class.h" />
150+
</ItemGroup>
151+
<ItemGroup>
152+
<ClCompile Include="AssemblyInfo.cpp" />
153+
<ClCompile Include="CppGenericsExample.cpp" />
154+
<ClCompile Include="pch.cpp">
155+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
156+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
157+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
158+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
159+
</ClCompile>
160+
</ItemGroup>
161+
<ItemGroup>
162+
<Image Include="app.ico" />
163+
</ItemGroup>
164+
<ItemGroup>
165+
<Reference Include="System" />
166+
<Reference Include="System.Data" />
167+
<Reference Include="System.Xml" />
168+
</ItemGroup>
169+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
170+
<ImportGroup Label="ExtensionTargets">
171+
</ImportGroup>
172+
</Project>

CppGenericsExample.vcxproj.filters

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ResourceCompile Include="app.rc">
19+
<Filter>Resource Files</Filter>
20+
</ResourceCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="Resource.h">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
<ClInclude Include="pch.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
<ClInclude Include="IGeneric.h">
30+
<Filter>Header Files</Filter>
31+
</ClInclude>
32+
<ClInclude Include="ClassTemplate.h">
33+
<Filter>Header Files</Filter>
34+
</ClInclude>
35+
<ClInclude Include="UInt32Class.h">
36+
<Filter>Header Files</Filter>
37+
</ClInclude>
38+
<ClInclude Include="UInt64Class.h">
39+
<Filter>Header Files</Filter>
40+
</ClInclude>
41+
<ClInclude Include="UInt16Class.h">
42+
<Filter>Header Files</Filter>
43+
</ClInclude>
44+
<ClInclude Include="UInt8Class.h">
45+
<Filter>Header Files</Filter>
46+
</ClInclude>
47+
</ItemGroup>
48+
<ItemGroup>
49+
<ClCompile Include="CppGenericsExample.cpp">
50+
<Filter>Source Files</Filter>
51+
</ClCompile>
52+
<ClCompile Include="AssemblyInfo.cpp">
53+
<Filter>Source Files</Filter>
54+
</ClCompile>
55+
<ClCompile Include="pch.cpp">
56+
<Filter>Source Files</Filter>
57+
</ClCompile>
58+
</ItemGroup>
59+
<ItemGroup>
60+
<Image Include="app.ico">
61+
<Filter>Resource Files</Filter>
62+
</Image>
63+
</ItemGroup>
64+
</Project>

IGeneric.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
generic <typename T>
4+
public interface class IGeneric
5+
{
6+
T ReturnResult();
7+
};

Resource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//{{NO_DEPENDENCIES}}
2+
// Microsoft Visual C++ generated include file.
3+
// Used by app.rc

UInt16Class.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include "ClassTemplate.h"
3+
4+
public ref class UInt16Class :
5+
public ClassTemplate<System::UInt16>
6+
{
7+
};

UInt32Class.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include "ClassTemplate.h"
3+
4+
public ref class UInt32Class :
5+
public ClassTemplate<System::UInt32>
6+
{
7+
};

UInt64Class.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include "ClassTemplate.h"
3+
4+
public ref class UInt64Class :
5+
public ClassTemplate<System::UInt64>
6+
{
7+
};

UInt8Class.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include "ClassTemplate.h"
3+
4+
public ref class UInt8Class :
5+
public ClassTemplate<System::Byte>
6+
{
7+
};

app.ico

40.4 KB
Binary file not shown.

app.rc

2.5 KB
Binary file not shown.

pch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// pch.cpp: source file corresponding to the pre-compiled header
2+
3+
#include "pch.h"
4+
5+
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.

0 commit comments

Comments
 (0)