-1

I am a learning c++ and this is an assignement, I'm trying to figure out why I get this error when I try to run the code

"... was not declared in this scope"

Please tell me how can I make the derived class see the variables in the main class

This is a header file.

template <typename A>
class aligner{
public:
    A filler;
    size_t max_size;
    std::vector<std::vector<A>*> vector;

    void add(std::vector<A> &v){
        vector.push_back(&v);
        if(v.size() > max_size){
            max_size = v.size();
        }
    }

    int count(){
        return vector.size();
    }

    void set_filler(A f){
        filler = f;
    }

    virtual void align() = 0;
    
    aligner(): filler(), max_size(0) {}

    ~aligner();
};

template <typename A>
class center_aligner: public aligner<A>{
public:
    void align(){
        for(std::vector<A> vec : vector){
            if(vec->size() < max_size){
                for(int i = 0; i < (max_size - vec->size); i++){
                    if(i%2==0){
                        vec.push_back(filler);
                    }else{
                        vec.insert(vec.begin(),filler);
                    }
                }
            }
        }
    }
    center_aligner();
    ~center_aligner();
};
m7913d
  • 9,476
  • 7
  • 25
  • 50
Happy
  • 1
  • 1
  • 1
    Please [don't post images of text](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). Copy-paste text *as text* into your questions. And please add comments on the lines in the code where you get them. – Some programmer dude May 22 '22 at 17:05
  • and also please paste the exact error message. – pm100 May 22 '22 at 17:11
  • why would you have a vector of pointers to vectors, that seem like a recipe for a mess. Why not just a vector of vectors – pm100 May 22 '22 at 17:13
  • Also, [your destructor should probably be virtual](https://stackoverflow.com/questions/461203/when-to-use-virtual-destructors) unless you want to come back to StackOverflow in about thirty minutes with a much worse error message. – Silvio Mayolo May 22 '22 at 17:15
  • Use `this->vector` , `this->max_size` and `this->filler` in derived class – P0W May 22 '22 at 17:16
  • @POW, why is 'this->' needed. Can you add an answer that explains it. I was surprised – pm100 May 22 '22 at 17:29
  • @POW thank you that was the problem now it works! – Happy May 22 '22 at 17:48

0 Answers0