C++?
                  
                  
                  
                  
                  
                  Выводит ошибка что не распознает функцию filter. 
                  
                  
                  
                  
                  
                  class utils {
                  
                  
                    template<typename T>
                  
                  
                    std::vector<T> static filter(const std::vector<T>& vec, std::function<bool(const T&)> cb) {
                  
                  
                    std::vector<T> filtred;
                  
                  
                    
                  
                  
                    for (const auto& i: vec) {
                  
                  
                      if (cb(i)) {
                  
                  
                        filtred.push_back(i);
                  
                  
                      }
                  
                  
                    }
                  
                  
                  
                  
                  
                    return filtred;
                  
                  
                   }
                  
                  
                  } 
                  
                  
                  
                  
                  
                  // Class Animal(type, subtype) 
                  
                  
                  
                  
                  
                  class Kingdom {
                  
                  
                  public:
                  
                  
                    std::vector<Animal> animals;
                  
                  
                  
                  
                  
                    void start() {
                  
                  
                       for (const Animal& animal: animals) {
                  
                  
                        // code
                  
                  
                  
                  
                  
                        auto filtred = utils::filter(animals, [](const Animal& a) {
                  
                  
                        return a.type == "dog" ;
                  
                  
                      });
                  
                  
                      }
                  
                  
                    }
                  
                  
                  }
                  
                  
                
Компилятор gcc 13v
Можно целый код посмотреть на godbolt. https://godbolt.org/z/rEfhxf57b
Обсуждают сегодня