what is templates and polymorphism in c++?
397445
A template is a mechanism for specifying the type of data to be handled by a class (or function) when we declare an object of that function (or when a call is made to that function).\n\n Polymorphism is the ability to respond in different ways based on the context in which the the call is made.There are different kinds of polymorphism.\n\nIn c++ polymorphism is acheived using overloading and overridding.\n\nyou can go through some books on C++ to understand it more clearly.
341242
Encapsulation; polymorphism and inheritance.\n\nEncapsulation lets you contain your data in objects that somewhat mirror 'real' objects.\nCustomer1 = new Customer (you would then populate your customer with public and private fields; perhaps everyone can see the public field that is the name of your customer; but the Customer object could also contain private fields; containing perhaps passwords and what that customer bought.) Encapsulation allows for data hiding; only other classes that have the correct permissions may access appropriate data. For example; another class that sends bills to your customers would also need to see the private data from the customer class. The data and methods that act on that data being enclosed in the methods allow you to change your class with little concern to the other classes that use the class you want to change. As long as you provide the same methods; the other classes will still be able to use the new class. The methods can also be either public or private; perhaps you want any class to be able to change the customer's phone number; but you would want to be more careful perhaps about changing the amount they owe. \n\nPolymorphism allows you to change your classes as required by using different input and output data; different types of data can use the same class. For example, a class could be written to print something; and can act differently if it is passed a string or a number. This allows you to use a class to do similar things with different types of data. It allows for the calling classes to be less concerned about what type of data you have; and more with what you want to do with that data.\n\nInheritance allows you to create new classes from existing classes. You could extend your Customer class by making a new HighSpendingCustomer. This new class would provide the same basic data and methods as your regular customer; but you could also add some new functionality to be more appropriately deal with the high-value customers. The new class would inherit the same functionality. This is often seen called 'is a' relationship. As in HighSpendingCustomer "is a" Customer; meaning that HighSpendingCustomer inherits from Customer.\n\nThe advantages of these are that they typically allow for easier code reuse (your customer class could be moved to a new application with little or no modification); easier to maintain (if you have a problem with a class; you can just change that class rather than dig through a huge program trying to find all occurances of a problem). As well; the classes tend to be smaller bits of code; it makes it easier to read and understand.\n\nThat's the 2 minute intro; hope it provides some value.
369213
1. Generic pointer is nothing but void*.\n2. A generic pointer/void* can be easily type casted to the desired datatype.\n3. Main differenc between the generic pointer and pointer of specific datatype: The void* is capable of pointing to the variable of any datatype whereas pointer of specific datatype say int* can point only to the variable of type int.\n4. Generic pointer is also used for taking the address of the variable alone.\n4. Whenever you are using void*, typecasting is required to perform the operation on the content that void* points to.\n5. Be careful when you are doing any arithmetic operation with void*.
616797
class ChildClass : public BaseClass\n{\n  // Class definition here\n};\nYes the constructor or any other function can be defined outside, as long as it was originally prototyped in the class definition:\n\nChildClass::ChildClass()\n{\n  // Function definition here\n}
653205
It lets the linker help the compiler piece together code that is in other files/libraries - for instance, if you do:\n\n#include <iostream>\n\nYou're going to be able to use the functions within the iostream library - otherwise, it wouldn't know where to go to get those function definitions.
1146701
These tutorials explain the C++ language from its basics up to the newest features of ANSI-C++, including basic concepts such as arrays or classes and advanced concepts such as polymorphism or templates. The tutorial is oriented in a practical way, with working example programs in all sections to start practicing each lesson right away.\n\nhttp://www.cplusplus.com/doc/tutorial/
32294
You may gain some knowledge of C++ in 21 days: that is, its syntax, generals of object orientation, templates and even maybe get a glimpse of the Standard Template Library. But then you have to deal with libraries that help you acheive usefull and high-level things. \nThat can take months.
60572
The typical rule is that if your class has at least one virtual function, you should always declare your class destructor as virtual.\n\nClasses with virtual functions are usually designed to be used as base classes for other classes and because you can assign a pointer to a derived class to a base class pointer, a virtual destructor is needed to make sure that the derived classes destructor is called.\n\nSee the section (and code example) entitled "Why are destructors not virtual by default?" in Bjarne Stroustrup's (creator of the C++ language) C++ FAQ at the link below.
314740
There are a few ways to do this, depending on the behavior you want. You can make a class that contains the array (constructor will take the size of the array). Then you implement/overload all the operators you are interested in. In these operators, you can overload [] to cause the index to wrap (if the size of the array was 10 and you did [10] you would get the 0'th element. Or you could have [10] return [9] element all the time. With templates:\n\ntemplate<class T, int n> class Array{\n\npublic:\nT& operator[](int i) {\nint j = i;\nif(i < 0){\n   j = 0;\n}\nif(i > n - 1){\n   j = n - 1;\n}\n\nreturn data[j];}\n\nprivate:\nT data[n];\n};\n\nor something like that.
344305
Yes Virtual methods in C++ can have implementations.
209710
C++ uses the same headers as C does. C++ has also some additional files for, e.g., streams and STL.
781094
Nobody is going to do your homework for you. \n\nIf you're supposed to write code examples that illustrate how two comparable programs might look, then do this. Write some simple programs in C, and then re-write the same program in C++ but put the functions your void main calls in a class and instantiate the class.
346423
check out http://www.planet-source-code.com - I don't do C++, but I use that site all the time, and it has great examples in source code form.
646616
class publication\n{\n   private :\n      char title[20];\n      float price;\n   public :\n      void getdata()\n      {\n          cin>>title;\n          cin>>price;\n      }\n};\nclass books :: public publication\n{\n   private :\n      int pagecount;\n   public :\n      void getdata()\n      {\n          cin>>pagecount;\n      }\n\n};\nclass tape :: public publication\n{\n   private :\n      int playing_time;\n   public :\n      void getdata()\n      {\n          cin>>playing_time;\n      }\n};
101346
A "protoype" is a statement that simply tells the program the format of a function call.\n\nLet's say that you create a function that adds up two doubles:\n\ndouble Add (double A, double B)\n{\n   return A + B;\n}\n\nNow in the header file associated with this function you would insert a function prototype:\n\ndouble Add (double A, double B);\n\nwhich you will notice looks very much like the function declaration itself.\n\nWhy do you need to do this? It is simple actually. If you were to call the function "Add" in another file, this other file does not know what types the parameters are, and what type the return value is. In order for the compiler to do its job, it needs to know this information.\n\nSo you simply "#include" the header file with the prototype, and the prototype does not actually perform anything other than telling the compiler that the function has two parameters, both of type double, and that the function returns a double.\n\nHope this helps!
964100
object-oriented programming, a virtual function or virtual method is a function whose behavior, by virtue of being declared "virtual", is determined by the definition of a function with the same signature furthest in the inheritance lineage of the instantiated object on which it is called. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP).\n\n\nThe concept of the virtual function solves the following problem:\n\nIn OOP when a derived class inherits from a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class functions overridden by the derived class, a problem then arises when a derived object has been cast as the base class type. When a derived object is referred to as being of the base's type, the desired function call behavior is ambiguous.\n\nThe distinction between virtual and not virtual is provided to solve this issue. If the function in question is designated "virtual" then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called.
1182636
go to a template web site - dont steal other people's work. Thats not cool. Visual Studio? You need an upgrade!