[英]Member reference base type 'std::vector<char> *[10]' is not a structure or union
I have the following problem: I´m trying to to some simple push in my class but its no working..我有以下问题:我正在尝试在我的班级中进行一些简单的推送,但它没有用。
#include <stdio.h>
#include <iostream>
#include <vector>
template <size_t B, size_t N, typename T = char>
class Number
{
private:
std::vector<T>* v[N];
int toBase(int valor);
public:
Number(int valor);
Number <B,N,T> suma(const Number<B,N,T>& sumando) const;
//ostream& write(ostream& os)const;
};
template <size_t B, size_t N, typename T>
Number<B,N,T>::Number(int valor)
{
toBase(valor);
}
template <size_t B, size_t N, typename T>
int Number<B,N,T>::toBase(int valor)
{
for(int i = 0; i < N; i++) {
int aux = valor % B;
v.push_back(aux); // PROBLEM HERE
}
}
template <size_t B, size_t N, typename T>
Number<B,N,T> Number<B,N,T>::suma(const Number<B,N,T>& sumando) const
{
//sumando.toBase();
}
The compiler says "member reference base type 'std::vector *[10]' is not a structure or union v.push_back(aux);"编译器说“成员引用基类型 'std::vector *[10]' 不是结构或联合 v.push_back(aux);”
I think the problem starts with my vector *v.我认为问题始于我的向量 *v。 Maybe i cant use push_back because its a pointer?
也许我不能使用 push_back 因为它是一个指针? I dont know..
我不知道..
Any ideas?有任何想法吗? Thank you.
谢谢你。
You're making this way more complicated than it needs to be and just confusing yourself.你让这种方式变得比它需要的更复杂,只是让你自己感到困惑。 Change your class to this
把你的班级改成这个
class Number
{
private:
std::vector<char> v;
int toBase(int valor);
public:
Number(int valor);
Number suma(const Number& sumando) const;
//ostream& write(ostream& os)const;
};
You're trying to split a number into it's digits and put them in a vector.您正在尝试将数字拆分为数字并将它们放入向量中。 So just write a simple class with a vector like above.
所以只需用上面的向量编写一个简单的类。 No templates or pointers or arrays are required for what you are trying to do.
您尝试执行的操作不需要模板、指针或数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.