Stack multiple custom modules using nn::Sequential

I implemented multiple modules inherited from torch::nn::Module to stack together within a nn::Sequential, though I got an error. Just to make it simple, in the following I made a simple example of this.

class SampleImpl: public nn::Module {
    nn::Conv2d conv1;
    SampleImpl(int c1, int c2, int k): nn::Module(),
    conv1(nn::Conv2dOptions(c1, c2, k))
      register_module("conv1", conv1);

    at::Tensor forward(at::Tensor& x) {
      return this->conv1(x);

int main(int argc, const char* argv[]) {
  nn::Sequential seq = nn::Sequential();
  seq->push_back(Sample(3, 12, 3));
  return 0;

And the following error appears:

error: static assertion failed: Modules stored inside AnyModule must not take references. Use pointers instead.
  336 |       torch::detail::check_not_lvalue_references<ArgumentTypes...>()

I have wrapped std::make_shared around it by using TORCH_MODULE macro but I don’t understand why I get this problem.

I found the problem, which is in the forward function arguments and its reference part should be removed.