H
Humble_Aspirant
Guest
I am writing a unit test using managed VS Test project.
I have a managed (CLI/C++) code as shown below
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);
}
}
}
I had build the above project as DLL.
In my test project I had made the code as below, referring to the above generated 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);
}
}
}
I had not shown all the other includes and using statement in this above code, like using namespase System, and include .
Now when I am trying to build the project I am getting the below error
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> > *'
I even tried c1->fillVec(&temp); to match the argement given in the error comments, still no luck.
Could anyone please help me out how to resolve the bottleneck?
I also tried adding the reference for ClassLibrary1 to UnitTestDemoProjTwo project from project->Add references; instead of #using. Now the error is coming as error C3767: 'ClassLibrary1::Class1::fillVec': candidate function(s) not accessible.
I think it is unable to access the managed func() through DLL, as I am passing unmanaged Containers(std::vector). need help in how to pass that vector.
Continue reading...
I have a managed (CLI/C++) code as shown below
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);
}
}
}
I had build the above project as DLL.
In my test project I had made the code as below, referring to the above generated 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);
}
}
}
I had not shown all the other includes and using statement in this above code, like using namespase System, and include .
Now when I am trying to build the project I am getting the below error
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> > *'
I even tried c1->fillVec(&temp); to match the argement given in the error comments, still no luck.
Could anyone please help me out how to resolve the bottleneck?
I also tried adding the reference for ClassLibrary1 to UnitTestDemoProjTwo project from project->Add references; instead of #using. Now the error is coming as error C3767: 'ClassLibrary1::Class1::fillVec': candidate function(s) not accessible.
I think it is unable to access the managed func() through DLL, as I am passing unmanaged Containers(std::vector). need help in how to pass that vector.
Continue reading...