简单 但 容易出错的地方

持续跟新中

1. 当使用容器定义指针类型的时候 要注意这个指针指向内容的变化

std::vector<char *> m_vPath;	
char str[20] = "hello world"; 
int main()
{
	for (int i = 0; i < 2; i++)
	{
		m_vPath.push_back(str);
		strcpy(str,"123455");
	}
}
上面本意是想将字符串 "hello world" 和  "123455"存入容器中 ,但是最后的结果是是"123455","123455"  ,指针指向的内容已经发生变化




2.多线程问题:使用了公用 变量经常容易出错



在类中声明了一个类对象 m_ftp,,但是在线程函数DownLoad中对该对象进行了操作, 这样导致在主线程中如果在使用到的该对象的时候可能发生改变,使用的时候要考虑该值的变化对程序可有影响

void CFtpDownLoadDlg::DownLoadFile(CString LocalFoldPath,CString ServerFilePath,CString ServerFileName)
{
	CString str;
	str = LocalFoldPath;
	if ( str.Right( 1 ) != "\\" )
		str += "\\" + ServerFileName;
	else
		str += ServerFileName;

	m_nCurUpFileSize = 0;
	//计算远程文件大小
	m_ftp.Size(( LPSTR )( LPCTSTR )ServerFilePath, &m_nCurUpFileSize, ftplib::image);

	//设置下载信息回调
	m_ftp.SetCallbackXferFunction( ( FtpCallbackXfer )CallbackXfer, this, 10240 );
	int a = m_ftp.Get(( LPSTR )( LPCTSTR )str, ( LPSTR )( LPCTSTR )ServerFilePath, ftplib::image );
	if ( a > 0 )
	{  
		//BeginFindLocFile();
	}
	else
	{
		//MessageBox( _T( "文件下载失败,请检查是否登录!" ), _T( "提示" ), MB_ICONWARNING );

	}

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值