Pointer to incomplete Class type is not allowed
First, let me say I do know there exist 1000 of this question on google. I just haven't found one that helped me.
Basically my program has 3 layers: 1) VB.net DLL --> 2) C++ / CLR uses the managed part to allow it to be used by the next --> 2) unmanaged C++
I get an error in my console test app... So here's the code
VB.net:
Code:
Public Class Add
public function Adding(Byval x as Double, Byval y as Double) as Integer
return x+y
end function
end class
C++/CLR
header AddingWrapper.h
Code:
#include "stdafx.h"
#include <msclr\auto_gcroot.h>
#using "Class1.dll"
class AddingWrapperPrivate;
class __declspec(dllexport) AddingWrapper {
private: AddingWrapperPrivate* _private;
public: AddingWrapper();
int Adding(double* x, double* y);
~AddingWrapper();
};
CPP --> AddingWrapper.cpp
Code:
#include "stdafx.h"
#include "AddingWrapper.h"
#using "Class1.dll"
#include <msclr\auto_gcroot.h>
using namespace System::Runtime::InteropServices;
class AddingWrapperPrivate {
public: msclr::auto_gcroot<Add^> add;
};
AddingWrapper::AddingWrapper()
{
_private = new AddingWrapperPrivate();
_private->add = gcnew Add();
};
int AddingWrapper:: Adding(double* x, double* y) {
return _private->add->Adding(*x, *y);
};
AddingWrapper::~AddingWrapper()
{
delete _private;
};
Finally, where the error occurs:
Test.cpp console app
Code:
#include "stdafx.h"
#include "AddingWrapper.h"
#include <iostream>
int main()
{
double x = 3;
double y = 3;
AddingWrapper* add;
*add->Adding(x, y); //pointer to incomplete class type is not allowed
std::cout << "here is the result";
return 0;
}
Any insight on how I could fix this thing? I'm about to throw it out the window
Re: Pointer to incomplete Class type is not allowed
As this is mainly a c++/cli question, I suggest you post this to the c++ cli forum here http://forums.codeguru.com/forumdisp...ed-C-and-C-CLI
This forum is for non Microsoft Visual Studio c++ issues.
[moderator could you move please]
Re: Pointer to incomplete Class type is not allowed
My bad, I just saw console application, so I posted here!
Re: Pointer to incomplete Class type is not allowed
However, the forum seems inactive :/
Re: Pointer to incomplete Class type is not allowed
It's not that active, but when a new thread is started there is usually a reply fairly quickly. :)
Re: Pointer to incomplete Class type is not allowed
[moved from C++ (Non Visual C++ Issues) forum]
Re: Pointer to incomplete Class type is not allowed
Actually, although a C++/CLI wrapper is involved, I'd say this is a native C++ question, at least at this point.
The reason for the error message you're referring to lies in your AddingWrapper.h: There you forward-declare a class named AddingWrapperPrivate, but only actually define it at the beginning of AddingWrapper.cpp. And using a pointer to or trying to instantiate that class is an error anywhere outside AddingWrapper.cpp. There's entirely no need for that class anyway: Simply make your auto_gcroot variable a direct member of AddingWrapper.
Also, you forgot to new a wrapper instance in your demo main(), the * when you reference it is superfluous (it is implied by the ->) and you need to pass the two parameters prefixed by & since they're pointers (what they don't need to be). Finally, there's no need to refer to the wrapper via pointer in this scenario - simply make the wrapper an ordinary local instance variable of main() -, or, if you're using the pointer, you need to delete it before leaving main().