I have been familiar with vs2015 tools to edit C + + in the past few days, (formerly used are vc++6.0). The discovery is really not easy to use, a simple small program will error a lot of questions you can not understand. I present to you the important question I have found.
When designing an object using a class template, it is common for the UF meta function to provide internal private member data access to the class, as shown in the following code, which defines the basic operation of a sequential table
1Template <typename t>2 classSqlistclass {//Sequential Table class template3T * data;//storing elements in a sequential table4 intLength//length of the storage order table5 Public:6Sqlistclass ();//construct initialization, allocate storage space, initialize table length to 07~sqlistclass ();//Destructors to free up allocated space8 voidCreateList (T a[],intn);//creates a sequential table with the given array element9 voidDisplist ();//output order table all elementsTen intListlength ();//get sequential table length One BOOLGetelem (intI, T &e);//to find the element value of an ordinal in a sequential table A intLocateelem (T e);//find ordinal by element value - BOOLListinsert (intI, T e);//Inserting data Elements - BOOLListdelete (inti);//Deleting data elements the - //other function algorithm implementations - //template <typename t> -FriendvoidReserve (Sqlistclass<t> & L);//Change The order Table element inverse example l={1,2,3,4} to l={4,3,2,1} + //template <typename t> -FriendBOOLDeleteelem (sqlistclass<t> & l,t E);//Delete the specified element value + //template <typename t> AFriendvoidMerge2 (sqlistclass<t> & L1, Sqlistclass<t> & L2, sqlistclass<t> &l3);//two-way merging algorithm at};
The implementation is not listed, and then I call it in the main function
1#include <iostream>2#include"SqListClass.cpp"3 using namespacestd;4 intMain ()5 {6sqlistclass<int>s1, S2;7 inta[4] = {1,2,3,4 };8S1. CreateList (A,4);9 Ten intb[3] = {5,7,9 }; OneS2. CreateList (b,3); A -sqlistclass<int>S3; - Merge2 (S1, S2, S3); the S3. Displist (); -}
The error will be as follows at compile time
Workaround: when defining template classes and template functions, you must add the <typename t> line statement
That
① when defining a template class, you can write it in the class definition header file (*.h)
Template <typename t>
Class a{
Class Body
};
In a class implementation (*.CPP), each member function is written like this
Template <typename t>
return value A<t>:: Function name (parameter list) {
function body
}
② to define a friend function in a template class It's also a function of defining template functions.
It is important to note that the definition of the template friend function in the (*.h) header file should be
Template <typename t>
friend return value function name (formal parameter list );
The template friend class in the (*.cpp) file is implemented as follows:
Template <typename t>
return value function name (formal parameter list)
{
function body
}
This will not be an error 2019. Problem solving
Similarly, when you design a template friend Class B, either declare the friend Class B in advance, or define the friend template Class B in Class A, or define the template friend Class B Don't forget to add
Template <typename t>
Link to Microsoft Error 2019 workaround https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=ZH-CN&k=k (LNK2019) &rd=true
Using vs2015 to edit C + + Template program error 2019