//CArrayDemo. CPP: defines the entry point of the console application,
//
# include "stdafx. H"
# include "CArrayDemo. H"
# ifdef _DEBUG
# define new DEBUG_NEW
# endif
//the only application objects
CWinApp theApp;
using namespace std;
Class A
{
Public:
A (int I LPCTSTR b)
: (I) (I)
, b (b)
{
}
Const int I;
Private:
LPCTSTR b;
};
Int _tmain (int arg c, TCHAR * argv [], TCHAR * envp [])
{
Int nRetCode=0;
HMODULE HMODULE=: : GetModuleHandle (NULL);
If (hModule!=NULL)
{
//initialize the MFC and display an error when failure
if (! AfxWinInit (hModule, NULL, : : GetCommandLine (), 0))
{
//TODO: change the error code to fit your needs
_tprintf (_T (" error: [English] failed to initiate the MFC \ n "));
NRetCode=1;
}
The else
{
//TODO: here is the behavior of the application code,
CArray Aarray;
}
}
The else
{
//TODO: change the error code to fit your needs
_tprintf (_T (" error: GetModuleHandle failed \ n "));
NRetCode=1;
}
Return nRetCode;
}
Error 1 error C2512: "A" : no suitable default constructor available c: \ program files \ Microsoft visual studio 10.0 \ \ vc atlmfc \ include \ afxtempl h 401 1 CArrayDemo
Error 2 error C2512: "A" : no suitable default constructor available c: \ program files \ Microsoft visual studio 10.0 \ \ vc atlmfc \ include \ afxtempl h 416 1 CArrayDemo
Mistake 3 error C2512: "A" : no suitable default constructor available c: \ program files \ Microsoft visual studio 10.0 \ \ vc atlmfc \ include \ afxtempl h 464 1 CArrayDemo
According to the above error I'm afxtempl. H in the void CArray
CArray CodePudding user response: You can this definition is,
Aarray. InsertAt or aarray. Add (,,) that can Add elements to an array, such as
But, your class A must add A function
LPCSTSR void ChangeData (int x, p)//this function can modify the content of A
{
I=a;
B=p;
}
Then where you use the
CArray Arr.
A, A.
Arr. ChangeData (x1, p1);//change data
Arr. Add (a);//add a to the array
.
Arr. ChangeData (xn, pn);
Arr. Add (a);
CodePudding user response:
Void A: : ChangeData (int x, LPCSTSR p)//this function can modify the content of A{
I=a;
B=p;
}
CodePudding user response:
CArray SetSize have A new operation, therefore A need to have A constructor with no parameters () A: I (0), b (0) {}Or CTypedPtrArray< pointer way; CPtrArray, A * & gt; Parray; His new delete
CodePudding user response:
CArray Aarray;Behind directly defined as member variables, and then it can be used to Add to Add elements