【发布时间】:2020-11-21 15:29:10
【问题描述】:
我有一个 c++ 中的线程池程序,可以在我的 Visual Studio 中的 Windows 机器上运行。我对 c++ 很陌生,从未在基于 linux 的系统上开发过它。我正在尝试使用 ubuntu 和 g++ 在 docker 容器中构建相同的程序。但是,我不断收到以下错误...
threadpool.h: In member function 'void ThreadPool::map(Func&&, Iterator, Iterator)':
threadpool.h:73:33: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class> struct ThreadPool::is_iterator'
73 | static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
| ^
threadpool.h:73:33: note: expected a type, got 'end'
如果我没看错,它说 end 需要是一个类型,这个错误是从下面的代码生成的......
template <typename Func, typename Iterator>
inline void map(Func&& f, Iterator begin, Iterator end)
{
static_assert(!is_iterator<Iterator>::value, "Begin argument needs to be an iterator");
static_assert(!is_iterator<end>::value, "End argument needs to be an iterator");
for (auto i = begin; i != end; ++i)
{
push(f, *i);
}
}
我认为我将 Iterator 声明为类型名,但它仍然存在问题。我唯一能想到的另一件事是我没有引入正确的库。我的 dockerfile 看起来像这样...
# Get the base Ubuntu image from Docker Hub
FROM ubuntu:latest
# Update apps on the base image
RUN apt-get -y update && apt-get install -y
# Install the Clang compiler
RUN apt-get -y install clang
# Install the G++ Compiler
RUN apt-get install -y g++
# Install Ruby
RUN apt-get install -y ruby
# Install Python
RUN apt-get install -y python
# Copy the current folder which contains C++ source code to the Docker image under /usr/src
COPY . /usr/src/threading
# Specify the working directory
WORKDIR /usr/src/threading
# Use G++ to compile the Test.cpp source file
RUN g++ -o threading threading.cpp -lpthread -std=c++17
# Run the output program from the previous step
CMD ["./threading"]
任何帮助将不胜感激。如有需要,我可以发布更多代码!
【问题讨论】: