Home > Back-end >  Rookie to do my homework, and a great god support... [online] o
Rookie to do my homework, and a great god support... [online] o

Time:10-16

C + + problem
Header files define the class:
#include
using namespace std;
Const int MaxSize=100;
Template
The class SeqList
{
Public:
SeqList () {length=0; }
SeqList (T a [], int n);
~ SeqList () {}
Int length () {return length; }
T Get (int I);//by a lookup
Int the Locate (T, x);//by value lookup
Void Insert (int I, T, x);
T Delete (int I);
Void PrintList ();
Private:
T data [MaxSize];

};
Template
SeqList & lt; T> : : SeqList (int n)
{
int i;
If (n> MaxSize)
Cout<& lt;" Parameters of the illegal ";
for(i=0; iCin> Data [I];
Length=n;
}
Template
Void SeqList : : Insert (int I, T, x)
{
int j;
If (length>=MaxSize)
Cout<& lt;" Overflow ";
If (i<1 | | i> Length + 1)
Cout<& lt;" Abnormal position ";
For (j=length; J>=I; J -)
Data [j]=data [j - 1);
Data [I - 1]=x;
Length++;
}
Template
T SeqList : : Delete (int I)
{
Int j, x;
If (length==0)
Cout<& lt;" Underflow ";
If (i<1 | | i> Length)
Cout<& lt;" Abnormal position ";
X=data [I - 1);
for(j=i; JData [1]=data [j];
Length -;
Return the x;
}
Template
T SeqList : : Get (int I)
{
If (i<1 | | i> Length)
Cout<& lt;" Find illegal ";
The else return data [I - 1);
}
Template
Int SeqList : : Locate (T, x)
{
int i;
for(i=0; iIf (data [I]==x) return the I + 1;
return 0;
}
Template
Void SeqList : : PrintList ()
{
If (I==0)
Cout<& lt;" Underflow ";
for(i=0; iCout}

Then the main function:

#include
using namespace std;
Int main ()
{
SeqList S (0);
Supachai panitchpakdi rintList ();
S.I nsert (3, 8);
CoutSupachai panitchpakdi rintList ();
Spyware doctor elete (5);
CoutSupachai panitchpakdi rintList ();
return 0;
}

Then the error display:


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Configuration: exe - Win32 Debug -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Compiling...
Cc. CPP
D: \ Microsoft visual studio \ myprojects \ exe \ seqlist h (32) : error C2244: 'SeqList : : SeqList : : SeqList ': unable to resolve the function overload
D: \ Microsoft visual studio \ myprojects \ exe \ seqlist h (33) : error C2954: template definitions always nest
D: \ Microsoft visual studio \ myprojects \ exe \ cc CPP (6) : error C2664: '__thiscall SeqList : : SeqList (const class SeqList & amp;) ': always convert parameter 1 from' const int 'to' const class SeqList & '
Reason: always convert from 'const int' to 'const class SeqList '
No constructor could take the source type, or constructor overload resolution was ambiguous
An error occurred when executing cl. Exe.

Exe. Exe - 1 error (s), and 0 warning (s)

CodePudding user response:

  • Related