About c++

Last Edited By Krjb Donovan
Last Updated: Mar 11, 2014 07:50 PM GMT

Question

Hello Sir,

           Can u tell how to get DATABASE Connectivity in c++ Development? and can we take Template Class as Base Class i.e. can we inherit from Template Class? Please Reply I m Looking  for your Reply....

Answer

1/ Database Connectivity:

ISO/ANSI standard C++ contains no support for database connectivity. That is far too specialised for the scope of such a standard. C++ is a very general purpose programming language and the standard C++ library support also tends to the general - language support, numeric functions, basic stream I/O with specific support for memory (string) and file streams, general collection types etc. Note: most of the standard C++ library is for hosted implementations of ISO/ANSI C++, the standard also describes a freestanding implementation type that is for use with systems with no supporting operating system (i.e. no host operating system), that has no library support at all other than that required for language support.

So any support you require must come from 3rd party additions. These could be either additions to the core language such as Embedded-SQL pre-compilers for a specific database (see for example http://en.wikipedia.org/wiki/Embedded_SQL ) or a C or C++ support library, which could either be, again, for a specific database, or access to a more general technology such as ODBC (for which you would require specific 'drivers' or other components for the database engines of interest). Note: C++ is able to easily use the facilities of C libraries.

For example if you are using the Microsoft compiler (Visual C++) on a Microsoft platform (i.e. Windows) then you could look at the Windows Development, Data Access and Storage sections of the MSDN Library ( http://msdn.microsoft.com/library/ee663264%28v=VS.85%29.aspx ), of which the Windows Data Access Components (Windows DAC or MDAC) SDK is probably of most interest.

Alternatively you can look at the raw access techniques and libraries provided with the specific database engine(s) of interest (e.g. the MySQL C API: http://dev.mysql.com/doc/refman/5.0/en/c.html ).

Then again maybe something a little higher up the abstraction levels would be of interest such as a Object Relational Mapper (ORM), such as Wt::Dbo ( http://www.webtoolkit.eu/wt/doc/tutorial/dbo/tutorial.html ), part of the Wt C++ web application library.

Oh, and some C++ GUI framework libraries tend a bit towards the everything including the kitchen sink approach to features so may contain some database support - the Microsoft Foundation Class (MFC) library's DAO, ODBC and OLE DB classes ( http://msdn.microsoft.com/en-us/library/fe1cf721.aspx ), or the Qt library's database module ( http://qt.nokia.com/products/library/modular-class-library#info_database ) for example.

You might like to search the Internet for sites that have C++ or C database libraries. To get you started you can look at the C++ Org site's C++ library database's database category ( http://c-plusplus.org/index.php?option=com_mtree&task=listcats&cat_id=54&Itemid=57 ) and the similar category on the thefreecountry.com site ( http://www.thefreecountry.com/sourcecode/database.shtml ).


2/ Inheriting from Class Template

Note: I assume you mean a class template, i.e.:

   template <typename T>
   class TC
   {
   ...
   };
   

and not a class that implements the template (method) pattern (see for example:

   http://login2win.blogspot.com/2008/06/c-template-pattern.html, 
   http://en.wikipedia.org/wiki/Template_method_pattern    

)

The answer is technically no. A template class is _not_ a class - it is a template (for the compiler) for producing a whole family of classes, each one specific and defined by its specific set of template arguments and called a specialisation of that template.

However, you can of course use a class template with template arguments as a base class:

   class C : public TC<int>
   {
   ...
   };

A class template can use another class template as a base class:

   template <typename U>
   class TC_Derived : public TC<int>
   {
   ...
   };

Or more commonly, some or all of the derived class template's template parameters are used to specialise the base class template:

   template <typename T, typename U>
   class TC_Derived2 : public TC<T>
   {
   ...
   };

One oddly common use is for the derived class to be used to specialise a base class template:

   class D : public TC<D>
   {
   ...
   };

This pattern crops up frequently enough that it has a name: the curiously recurring template pattern (CRTP) (see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern )


Hope this helps.

Advertisement

©2024 eLuminary LLC. All rights reserved.