I have a vector of type Tab
, but when I call class functions on the vector of Tab
s I get no output. However, I don't receive any errors either.
If you know what an Android launcher is, then this is supposed to be a simple console-based testcase of an Android launcher with categorized tabs that allow you to scroll to another tab.
main.cpp
#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++;
}
}
Tab.h
#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
Tab.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;
}
I know in my code I return some addresses and some strings, but that was just to test to see if one method would work over the other, but it doesn't.