I have the following problem. I´m just trying to output a vector but it says "invalid operands to binary expression ('std::ostream' (aka 'basic_ostream') and 'const std::vector')"
Code:
#include <stdio.h>
#include <iostream>
#include <vector>
template <size_t B, size_t N, typename T = int>
class Number
{
private:
std::vector<T> v[N]; // Vector que contendrá el numero desglozado
void toBase(int valor);
public:
Number(int valor); // Constructor
Number <B,N,T> suma(const Number<B,N,T>& sumando) const;
std::ostream& write(std::ostream& os)const;
};
template <size_t B, size_t N, typename T>
Number<B,N,T>::Number(int valor)
{
toBase(valor);
std::cout << write() << std::endl;
}
template <size_t B, size_t N, typename T>
void Number<B,N,T>::toBase(int valor)
{
for(int i = 0; i < N; i++) {
int aux = valor % B;
v[i].push_back(aux);
}
}
template <size_t B, size_t N, typename T>
std::ostream& Number<B,N,T>::write(std::ostream& os) const
{
for(int i = 0; i < N; i++){
os << v[i] << std::endl;
}
}
I thought the problem was that i was trying to output the vector with a simple for loop. So i tried to output it with an ostream but i have the same error. So the ostream its ok i think. Just the outputting vector is the problem and i dont know why. Any ideas? Thanks you!
main:
#include <stdio.h>
#include <iostream>
#include "number.hpp"
int main() {
Number<2,10> N1(100);
Number<2,10> N2(200);
}
v
is an array of vectors, for starters. - Shawnv
is an array of vectors, for starters. Vectors don't come with anoperator<<()
... - Shawnstd::cout << write()
and with the fact thatwrite
is a non-void function that doesn't return anything. - molbdnilo