我正在关注this question以选择合适的容器,但我遇到了问题。
我有一个selector
类必须推回指针向量,但正确的类依赖于它的维度(向量为1,对于矩阵为2):
class selector
{
struct formValues : std::vector<coolvector<double>*>, std::vector<coolmatrix<double>*> { };
formValues maps;
public:
selector() { };
template<unsigned int formdim, typename F>
void operator+=(const form<formdim, F> &f)
{
typedef typename form<formdim, F>::storage_type storage_type;
typedef typename std::vector<storage_type*> pointer_type;
// Push to the right vector
formValues<pointer_type> &m = maps;
m.push_back(f.storage.get());
}
};
form类具有维度和存储,同样取决于维度,使用共享指针:
template <bool, class if_true, class if_false>
struct type_switch
{
typedef if_false type;
};
template <class if_true, class if_false>
struct type_switch<true, if_true, if_false>
{
typedef if_true type;
};
template <class T> class coolvector {};
template <class T> class coolmatrix {};
template<unsigned int formdim, typename F>
class form
{
public:
form() = delete;
form(const std::string &s) : type(s)
{
storage = std::make_shared<storage_type>();
}
std::string type;
typedef typename type_switch<formdim == 1, coolvector<double>, coolmatrix<double>>::type storage_type;
std::shared_ptr<storage_type> storage;
};
class oneform : public form<1, oneform>
{
public:
oneform() = delete;
oneform(const std::string &s) : form(s) { };
double operator()(unsigned int i) { return i * 2; };
};
class twoform : public form<2, twoform>
{
public:
twoform() = delete;
twoform(const std::string &s) : form(s) { };
double operator()(unsigned int i, unsigned int j) { return i * 2 + j * 20; };
};
问题在于selector::operator+=
我收到此错误:
main.cpp:77:19: error: expected unqualified-id
formValues<pointer_type> &m = maps;
^
任何提示都表示赞赏!
答案 0 :(得分:2)
.img0, .img1, .img2, .img3 {position: relative}
不是模板,因此您无法撰写formValues
。
你的意思是
formValues<pointer_type>
获取pointer_type& m = maps;
的适当基类子对象。