我坚信使用单元测试作为构建大型多平台应用程序的一部分.我们目前正计划在单独的项目中进行单元测试.这有利于保持我们的代码库清洁.但是,我认为这会将测试代码与单元的实现分开.你怎么看待这种方法,有没有像JUnit这样的工具用于c ++应用程序?
考虑这个构造函数: Packet() : bits_(0), datalen_(0), next_(0) {}
注意bits_
,datalen_
并且next_
Packet类中的字段定义如下:
u_char* bits_;
u_int datalen_;
Packet* next_;
Run Code Online (Sandbox Code Playgroud)
这部分构造函数意味着什么? bits_(0), datalen_(0), next_(0)
所以我是第一年的计算机科学专业的学生,因为在我的最终项目中,我需要编写一个带有字符串向量的程序,并将各种函数应用于这些.不幸的是,我真的很困惑如何使用指针将向量从函数传递给函数.下面是一些示例代码,以便了解我在说什么.当我尝试使用任何指针时,我也会收到错误消息.
谢谢.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
vector<string>::pointer function_1(vector<string>::pointer ptr);
void function_2(vector<string>::pointer ptr);
int main()
{
vector<string>::pointer ptr;
vector<string> svector;
ptr = &svector[0];
function_1(ptr);
function_2(ptr);
}
vector<string>::pointer function_1(vector<string>::pointer ptr)
{
string line;
for(int i = 0; i < 10; i++)
{
cout << "enter some input ! \n"; // i need to be able to pass a reference of the vector
getline(cin, line); // through various functions, and have the results
*ptr.pushback(line); // reflectedin …
Run Code Online (Sandbox Code Playgroud)