函数定义错误,类没有成员
Posted
技术标签:
【中文标题】函数定义错误,类没有成员【英文标题】:Function definition error, class has no member 【发布时间】:2014-11-22 03:24:52 【问题描述】:我正在创建一个使用 Visual Studio 和 Windows 窗体计算工人工作时间的 UI 的初学者级项目。我的错误出现在以下函数中,我尝试将值分配给文本框。所有“ToDouble”都显示错误类“System::String”没有成员“ToDouble”,并且接近尾声(S“F”)显示标识符 S 未定义且预期)
void CalculateWeeklyHours(void)
double monday, tuesday, wednesday, thursday,
friday, saturday, sunday, totalHours;
monday = this->txtMonday->Text->ToDouble(0);
tuesday = this->txtTuesday->Text->ToDouble(0);
wednesday = this->txtWednesday->Text->ToDouble(0);
thursday = this->txtThursday->Text->ToDouble(0);
friday = this->txtFriday->Text->ToDouble(0);
saturday = this->txtSaturday->Text->ToDouble(0);
sunday = this->txtSunday->Text->ToDouble(0);
totalHours = monday + tuesday + wednesday + thursday +
friday + saturday + sunday;
this->txtTotalHours->Text = totalHours.ToString(S"F");
throw(gcnew System::NotImplementedException);
完整代码在这里http://ideone.com/ySgxp1
c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(604): error C3921: Use of S-prefixed strings requires /clr:oldSyntax command line option 1> 使用 /clr 编译时,存在从字符串文字类型到 System::String^ 的隐式转换。如果需要避免歧义,请转换为 System::String^ 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(594): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(595): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(596): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(597): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(598): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(599): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>c:\users\administrator\documents\visual studio 2012\projects\form1\form1\TimeSheet1.h(600): error C2039: 'ToDouble' : is not a member of 'System::String' 1> c:\program files (x86)\reference assembly\microsoft\framework.netframework\v4.5\mscorlib.dll :参见“System::String”的声明 1>TimeSheet1.cpp(7):警告 C4829:main 函数的参数可能不正确。考虑'int main(Platform::Array^ argv)'
【问题讨论】:
【参考方案1】:您应该使用来自System.Convert
类的ToDouble(string)
。
http://msdn.microsoft.com/en-us/library/zh1hkw6k(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
【讨论】:
我尝试了这种格式,但它不起作用。我粘贴了错误,看来我需要转换。以上是关于函数定义错误,类没有成员的主要内容,如果未能解决你的问题,请参考以下文章