0

I'm trying to use perfect forwarding on my custom vector class (to mimic the std::vector "emplace_back" in a sense) and to export it from the dll it is defined in.

  • repeated_ptr_field.hpp

     template<typename TMessage>
     class RepeatedPtrField
     {
     private:
         std::vector<std::unique_ptr<TMessage>> v_;
    
     public:
         RepeatedPtrField(const RepeatedPtrField& other) = delete;
         RepeatedPtrField& operator=(const RepeatedPtrField& other) = delete;
         RepeatedPtrField();
    
         // Some things...
    
         TMessage* Add()
         {
             // This one is ok so far
             v_.push_back(std::make_unique<TMessage>());
             return v_.back().get();
         }
    
         template <typename ...Args>
         TMessage* Add(Args&& ...args)
         {
             // This one is giving me headaches
             v_.push_back(std::make_unique<TMessage>(std::forward<Args>(args)...));
             return v_.back().get();
         }
    
         // Some other things...
     };
    
  • repeated_ptr_field.cpp

     template __declspec(dllexport) Value* RepeatedPtrField<Value>::Add(double&&, Currency&&, long&&);
    
  • value.hpp

     class Value : public Message
     {
         // Some things...
    
     public:
         // Both constructors defined in .cpp
         __declspec(dllexport) Value();
         __declspec(dllexport) Value(double value, Currency ccy, long timestamp); // This is the constructor that should be used by the Add(args...) method.
    
         // Some other things...
     };
    

And I'm getting the compiler error: 'Value::Value': no overloaded function takes 3 arguments

loyd.f
  • 163
  • 1
  • 11
  • OT: Having a `repeated_ptr_field.cpp` could cause you other problems: [https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – drescherjm Apr 26 '21 at 17:09
  • Are you sure you actually implemented `Value::Value(double, Currency, long)` and not just declared it inside the header? Could you make the example more replicable? For me [this works](https://onlinegdb.com/ByPdaRBDd) without `__declspec(dllexport`. – 2b-t Apr 27 '21 at 18:54

0 Answers0