【发布时间】:2016-12-31 16:13:07
【问题描述】:
我想知道有什么方法可以同时访问三个容器。 我有这样的课:
class DataContainer
{
private:
std::vector<Rental*> rentals;
std::vector<Vehicle*> vehicles;
std::vector<Client*> clients;
public:
DataContainer();
bool loadObjects();
bool createRentals();
std::string showVehicles() const;
std::string showClients() const;
std::string showDetails() const ;
std::tuple< std::vector<Vehicle*>type1, std::vector<Client*>type2, std::vector<Rental*>type3 > getContainers();
virtual ~DataContainer();
};
我希望有可能从其他类访问这些容器,这就是为什么我想设置一些吸气剂,但我的问题来了。我不知道我是否做错了什么,但我得到的错误是:
include\DataContainer.h|74|error: template argument 1 is invalid|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 1 second(s)) ===|
我的函数如下所示:
std::tuple< std::vector<Vehicle*>type1, std::vector<Client*>type2, std::vector<Rental*>type3 > DataContainer::getContainers()
{
return std::make_tuple(vehicles,clients,rentals);
}
希望有人能给我一些提示,如果这对我正在开发 C++11 有任何影响。
【问题讨论】:
-
std::tuple<T1, T2, T3>期望T1, T2, T3是类型。std::vector<Vehicle*>type1不是有效类型。std::vector<Vehicle*>是。 -
type2等不应出现在std::tuple< std::vector<Vehicle*>type1, std::vector<Client*>type2, std::vector<Rental*>type3 > getContainers();行中。然而,这看起来就像是一开始就相当糟糕的类设计。 -
即使错误得到修复,您最终也可能会复制 很多 指针以返回三个向量。你想达到什么目的?