0

我正在使用托管 VS 测试项目编写单元测试。
我有一个托管(CLI/C++)代码,如下所示

namespace ClassLibrary1 {
   public ref class Class1
        {
        std::vector<int>* vec1;
    public:
            Class1() {
                this->vec1 = new std::vector<int>();
            }
    void fillVec(std::vector<int> inp) {            
                for (std::vector<int>::iterator it = inp.begin(); it != inp.end(); ++it) {
                    this->vec1->push_back(*it);
                }
        }
}

我已经将上述项目构建为 DLL。
在我的测试项目中,我参考上面生成的 dll 编写了如下代码。

#using "ClassLibrary1.dll" as_friend
namespace UnitTestDemoProjTwo
{
[TestClass]
    public ref class UnitTest
    {
        ClassLibrary1::Class1 ^c1;
    public: 
[TestInitialize()]
        void MyTestInitialize()
        {
            c1 = gcnew ClassLibrary1::Class1;               
        }
[TestMethod]
        void TestMethod03()
        {
            std::vector<int> temp;
            temp.clear();
            temp.push_back(12);
            temp.push_back(11);
            c1->clearVec();//func in Class1 which will clear the vector
            c1->fillVec(temp);
            Assert::AreEqual(c1->retSizeOfVec(), 2);
        }
    }
}

我在上面的代码中省略了所有其他的 include 和 using 语句,比如using 命名空间 Systeminclude
现在,当我尝试构建项目时,出现以下错误

error C2664: 'void ClassLibrary1::Class1::fillVec(std::vector<int,std::allocator<int> > *)': 
    cannot convert argument 1 from 'std::vector<int,std::allocator<_Ty>>' to 'std::vector<int,std::allocator<int> > *'

我什至试过c1->fillVec(&temp); 匹配错误注释中给出的参数,仍然没有运气。

谁能帮我解决瓶颈问题?

4

0 回答 0