Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

面试题1考虑异常安全的解法有误 #57

Open
pusidun opened this issue Aug 4, 2019 · 4 comments
Open

面试题1考虑异常安全的解法有误 #57

pusidun opened this issue Aug 4, 2019 · 4 comments

Comments

@pusidun
Copy link

pusidun commented Aug 4, 2019

代码仓库没有给出,书上给出了

//copy operator
CMyString& CMyString::operator=(const CMyString& str)
{
	if(m_pData != &str)
	{
		CMyString tmpData(str);
		
		char *ptmp = tmpData.m_pData;
		tmpData.m_pData = m_pData;
		m_pData = ptmp;
	}
	return *this;
}

m_pData是private的,书上写的有点问题

@zhiqiang-hhhh
Copy link

private 在这里没影响吧

@pusidun
Copy link
Author

pusidun commented Nov 17, 2019

@hezhiqiangTS
tmpData.m_pData 这里,private不能这么写吧

@acxmx
Copy link

acxmx commented May 14, 2020

private 在这里没影响吧

不懂,可以解释一下吗?

@acxmx
Copy link

acxmx commented May 14, 2020

同问,tmpData不能直接访问它的private成员吧?需要通过成员函数访问的吧?
但是自己写代码测试也是能通过,现在很疑惑,求懂的同学解答!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants