我用 C++ 编程了一段时间,我认为尝试从 Visual C++ 开始并制作一个计算器会很有趣。
好的,所以我设计了一个简单的窗口,有两个文本框和一个将两个框添加在一起的按钮。 我知道我不需要为此提供功能,但我喜欢尝试并学习它们。 因此,当我在设计 View 中时,我双击按钮以获取其代码。 在代码的开头,我创建了两个变量,并为它们赋值。 现在我想调用一个带有两个参数并返回附加值的函数。 这就是令人讨厌的地方,因为我收到此错误:
error C3861: 'addFunction': identifier not found
我还有一个问题。 我有一个 if() 来确保两个文本框都有一个值。 if 是这样的:
if(a && b)
编译器给我这个错误:
error C2676: binary '&&' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
是的,其中一个变量是一个字符串,但它应该仍然有效,对吧?
我希望你能帮助我!
编辑 我已经解决了这两个问题,但现在又出现了一些问题。
一个错误是提示这个:
textstring = DecryptedBox->Text;
还有一个错误,在编译器日志中出现了 10 次
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring(707): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(std::basic_string<_Elem,_Traits,_Ax> &&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
这是什么意思?
最佳答案
我假设字符串 a && b 都是字符串值。所以你应该做类似的事情
if(a.empty() || b.empty())
std::cout << "Values don't exist in one of the boxes" << std::endl;
而addFunction identifier not found则表示编译器找不到addFunction函数。你声明了吗?是不是在另一个类中,而您没有包含?
关于c++ - Visual C++ 函数问题(及其他),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4935862/