我有一个类型的向量Tab
,但是当我在 s 的向量上调用类函数时,Tab
我没有得到任何输出。但是,我也没有收到任何错误。
如果您知道什么是 Android 启动器,那么这应该是一个简单的基于控制台的 Android 启动器测试用例,带有分类选项卡,允许您滚动到另一个选项卡。
主文件
#include <iostream>
#include <vector>
#include <string>
#include "Tab.h"
void addVectOfTabs(std::vector<Tab>& tabs);
void swipe(std::vector<Tab>& tabs);
int main()
{
std::vector<Tab> tabs;
tabs.reserve(3);
addVectOfTabs(tabs);
swipe(tabs);
return 0;
}
void addVectOfTabs(std::vector<Tab>& tabs)//adds values to the vector(arrayList) of tabs
{
Tab google ("Google", "0001", "#ffffff");
Tab xPosed ("XPosed", "0002", "#aaaaaa");
Tab custom ("Custom", "0003", "#dddddd");
tabs.push_back(google);//don't have to use new keyword for whatever reason (C++ is weird)
tabs.push_back(xPosed);
tabs.push_back(custom);//just some bs values for these
std::cout<<google.getTabColor(); //this works
}
void swipe(std::vector<Tab>& tabs)//automated simulated swiping
{
for(int i=0;i<tabs.size();i++)
{
int tabSize = tabs[i].getAppsInDrawerSize();
tabs[i].showName();
std::cout << "\n\n\n" << "**********************" << tabs[i].getTabID() << "*************";
std::cout << "\n" << tabSize;
for(int j=0;j < tabSize;j++)
{
std::cout<<"\nYou are at app " << (j+1) << " of " << tabSize;
}
if (i>tabSize)//I wrote this code late last night and have no clue what I was thinking with this ine
i++;
}
}
选项卡
#ifndef TAB_H
#define TAB_H
#include <vector>
#include <string>
#include <array>
class Tab
{
public:
Tab();
virtual ~Tab();
Tab(const Tab& other);
Tab(std::string tabName, std::string tabID, std::string tabColor);
std::array<int,10>& getAppsInDrawer();
std::string getTabName();
std::string& getTabID();
std::string& getTabColor();
int getAppsInDrawerSize();
void showName(); //can't access
protected:
private:
std::array<int, 10> appsInDrawer; //vector is like arraylist in Java; simulation of apps in the app drawer
void populateAppsInDrawer();
std::string tabName;
std::string tabID;
std::string tabColor;
};
#endif // TAB_H
选项卡.cpp
#include <string>
#include <iostream>
#include "Tab.h"
Tab::Tab()
{
//ctor
}
Tab::~Tab()
{
//dtor
}
Tab::Tab(const Tab& other)
{
//copy ctor
}
Tab::Tab(std::string tabN, std::string tabId, std::string tabClor): tabName(tabN), tabID(tabId), tabColor(tabClor)
{
}
std::array<int,10>& Tab::getAppsInDrawer()
{
return appsInDrawer;
}
std::string Tab::getTabName()
{
return tabName;
}
std::string& Tab::getTabID()
{
return tabID;
}
std::string& Tab::getTabColor()
{
return tabColor;
}
void Tab::populateAppsInDrawer()//for simulation purposes
{
for(int i=0;i<10;i++)
{
appsInDrawer[i]=i+1;//adds an item; similar to arrayList.add()
}
}
int Tab::getAppsInDrawerSize()
{
return appsInDrawer.size();
}
void Tab::showName()
{
std::cout << tabName;
}
我知道在我的代码中我返回了一些地址和一些字符串,但这只是为了测试一种方法是否适用于另一种方法,但事实并非如此。