Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Objective C

Dynamic Class Factory

Rate me:
Please Sign up or sign in to vote.
4.38/5 (19 votes)
18 Nov 2018CPOL3 min read 91.1K   1.4K   29  
An article about class factory with dynamic subscription / auto registration
// SimpleDynCreate.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include "ClassFactory.h"
#include "SampleBase.h"

int _tmain(int argc, TCHAR* argv[])
{
	CSampleBase* pBase = NULL;

	TCHAR tcStringToTranslate[] = _T("One or two tiers ?");
	
	// print starting status
	std::cout << tcStringToTranslate << std::endl;
	
	TCHAR tcsDelimits[] = _T(" ");
	TCHAR * tcToken = _tcstok(tcStringToTranslate, tcsDelimits);

	while (tcToken)
	{
		pBase = CClassFactory< TCHAR*, CSampleBase, _tcsless >::CreateInstance(tcToken);

		if (pBase)
		{
			std::cout << pBase->Display();
			delete pBase;
		}
		else
		{
			std::cout << tcToken;
		}

		 std::cout << _T(" ");

		tcToken = _tcstok(NULL, tcsDelimits);
	}

	std::cout << std::endl;

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions