-
June 8th, 2016, 12:56 PM
#1
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
-
June 8th, 2016, 01:51 PM
#2
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]
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 8th, 2016, 01:55 PM
#3
Re: Pointer to incomplete Class type is not allowed
My bad, I just saw console application, so I posted here!
-
June 8th, 2016, 01:56 PM
#4
Re: Pointer to incomplete Class type is not allowed
However, the forum seems inactive :/
-
June 8th, 2016, 02:22 PM
#5
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 8th, 2016, 03:57 PM
#6
Re: Pointer to incomplete Class type is not allowed
[moved from C++ (Non Visual C++ Issues) forum]
Victor Nijegorodov
-
June 9th, 2016, 06:08 AM
#7
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().
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|