c++:在main方法中运行函数
c++: Running a function in main method
我是C++新手,试图弄清楚一些事情。我面临且不确定的问题之一是从main()方法调用函数时收到的超出范围的错误:
User@PC /cygdrive/c/Documents and Settings/---/folder
$ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:90:9: error: ‘test01’ was not declared in this scope
test01();
测试的代码.cpp如下。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class stringStuff {
vector<string>* elements;
int frontItem;
int rearSpace;
int upperBound;
public:
stringStuff(int capacity) {
vector<string>* elements = new vector<string>(2*capacity);
frontItem = capacity;
rearSpace = capacity;
upperBound = 2 * capacity;
}
virtual void test01(){
stringStuff* sd = new stringStuff(100);
// test code here
}
};
/** Driver
*/
int main() {
test01();
}
我在这里做错了什么?
test01
是类中的成员函数。您必须实例化类,创建一个对象才能使用它。
这将在你C++书的早期介绍,我强烈建议你在下次尝试之前阅读更多内容。
相关文章:
- 无法获取菜单选择以运行函数.C++
- 为什么std::async使用同一个线程运行函数
- MINGW - 正确运行函数所需的 cdecl
- 如何在 C 中使用空的 main() 方法运行函数?
- 运行函数作为 constexpr 和不作为 constexpr
- 如何在全局变量的构造函数之前运行函数
- 在 Cap'n Proto RPC 服务器中定期运行函数
- 为什么当我在 c++ 中运行函数时,我的代码显示数字 53
- CLang:在 std::thread 中运行函数会导致结构创建BAD_ACCESS
- 如何使用 TBB 在单个线程中运行函数
- 我在运行函数 GetVolumeInformation() 时得到非常随机的结果
- 如何使用 boost::asio io_service 运行函数异步
- Qt - 在其他线程上运行函数
- 在一组模板化对象上运行函数
- pybind11:属性错误:尝试从 py 文件运行函数时,模块'XXX'没有属性'YYY'
- 添加按钮以通知运行函数的通知
- 如何在程序后台运行函数(特别是自动保存函数)?QT / C++
- Qt - 在单独的线程中运行函数
- 如何在单独的线程上运行函数(如果线程可用)
- 如何发出编译和运行C++函数的 LLVM IR