static"不应在文件范围内定义的成员函数上使用
2013-09-21 20:42
1591 查看
转自:
http://zhidao.baidu.com/link?url=3cG_RJDfBQnzKzhnKaoL4wTkT_C0JDmdn0MH4eSPDe9clrnR4d1iJkYxWm88Z2QFGrUwYMBHuqPq5tzn9uYZKK
解决:
static只需要加在类定义里,类定义外面的函数定义前不能写static。
void SavingsAccount::modifyInterestRate(double interestRate) // 去掉前面的static
{
annualInterestRate=interestRate;
}
http://zhidao.baidu.com/link?url=3cG_RJDfBQnzKzhnKaoL4wTkT_C0JDmdn0MH4eSPDe9clrnR4d1iJkYxWm88Z2QFGrUwYMBHuqPq5tzn9uYZKK
错误信息:“static”不应在文件范围内定义的成员函数上使用 //SavingsAccount.h #ifndef SAVINGS_ACCOUNT_H #define SAVINGS_ACCOUNT_H class SavingsAccount { public: SavingsAccount(double); static double annualInterestRate; double calculateMonthlyInterest(); static void modifyInterestRate(double); double getNewSavingsBalance(double); void setSavingsBalance(double); private: double savingsBalance; }; #endif 错误的箭头是指到这个函数的定义上来的,作业的要求是:一定要modifyInterestRate这个函数来初始化static double annualInterestRate的值,求助,谢谢! static void SavingsAccount::modifyInterestRate(double interestRate) { annualInterestRate=interestRate; }
解决:
static只需要加在类定义里,类定义外面的函数定义前不能写static。
void SavingsAccount::modifyInterestRate(double interestRate) // 去掉前面的static
{
annualInterestRate=interestRate;
}
相关文章推荐
- C++使用static的错误:无法解析的外部符号、“static”不应在文件范围内定义的成员函数上使用 .
- C++使用static的错误:无法解析的外部符号、“static”不应在文件范围内定义的成员函数上使用
- C++使用static的错误:无法解析的外部符号、“static”不应在文件范围内定义的成员函数上使用
- 【c++笔记七】教你使用"const类型的对象、成员函数"和"static类型的成员函数、变量"
- static函数 函数调用缺少参数列表;请使用“&XXX”创建指向成员的指针;类的static成员函数
- Effective Modern C++ 条款22 当使用Pimpl Idiom时,在实现文件中定义特殊成员函数
- 多个".h"文件中声明及定义 全局变量和函数
- 为什么在C++使用pthread_create()的时候,类成员函数做线程的处理函数必须要定义成static类型的?
- 为什么在C++使用pthread_create()的时候,类成员函数做线程的处理函数必须要定义成static类型的?
- 在函数和包含头文件中使用extern "C" 的作用
- c++11 条款22:当使用Pimpl(指向实现的指针)时,在实现文件里定义特定的成员函数
- C++学习小记(使用定义在其他.cpp文件中的变量或函数)
- IIS 中 "另一个程序正在使用此文件,进程无法访问!" http://www.cnblogs.com/publicbill/archive/2007/05/29/763844.html
- Python基础语法(2)——字典、函数定义使用、控制流(if&for&while)
- 通用组件"浏览服务器文件"的使用
- win7 IIS7 "另一个程序正在使用此文件,进程无法访问" 解决方法
- C++中各种数据成员及成员函数的定义及使用
- [C/C++]在头文件中使用static定义变量意味着什么
- [翻译] Effective C++, 3rd Edition, Item 45: 用 member function templates(成员函数模板) 接受 "all compatible types"(“所有兼容类型”)
- 在头文件中使用static定义变量意味着什么