|
|
Here is the code:
<br />
#include "class2.h"<br />
<br />
class A<br />
{<br />
public:<br />
A(void) {}<br />
~A(void) { if ( _cls2) delete _cls2; }<br />
public:<br />
void Create(void) { _cls2 = new B(this); }
void Display(void) { printf("from A"); }<br />
private:<br />
B * _cls2;<br />
};<br />
<br />
#include "class1.h"<br />
<br />
class B<br />
{<br />
public:<br />
B(A * ptr) : _cls1(ptr) {}<br />
~B(void) {}<br />
public:<br />
void Do(void) { _cls1->Display(); }<br />
private:<br />
A * _cls1;<br />
};<br />
But I got error on compiling
How to solve it?
|
|
|
|
|
in one of the files, before the definition of the class, declare the other one.
for example :
class A;
class B {
};
|
|
|
|
|
You mean combine two .h files into one .h file?
Is it possible to solve it in two .h files?
THX for your quick reply
|
|
|
|
|
shaohao wrote: You mean combine two .h files into one .h file?
no
file A.h
#include "B.h"
class A {
};
file B.h
#include "A.h"
class A;
class B {
};
|
|
|
|
|
But I think it should be:
<br />
file A.h<br />
<br />
#include "B.h"<br />
<br />
class A {<br />
};<br />
<br />
file B.h<br />
<br />
class A;<br />
<br />
class B {<br />
};<br />
Any idea?
Is it right?
-- modified at 9:11 Friday 10th March, 2006
|
|
|
|
|
Yes - this is correct. It compiles without a problem.
gmileka
|
|
|
|
|
i thought it would be better to make a new tread for this one.
i am trying to get this code to work, but i don't know what i'm doing wrong..
i know this much....
i have a class library(.net) called fooManaged and its automatical created fooManaged.h. and i created UnManaged.h
in the UnManaged.h file i have this code.....
#include iostream
#include vcclr.h
using namespace std;
class Foo
{
public:
Foo();
~Foo();
void DoSomeFoo();
};
// constructor
Foo::Foo()
{
cout<<"Constructor called!"<<endl;
}
destructor
foo::~foo()=""
{
cout<<"destructor="" called"<<endl;
}
="" some="" method
void="" foo::dosomefoo(void)
{
cout<<"do="" something="" funny!"<<endl;
cout<<"burrrp!"<<endl;
}
in="" foomanaged.h="" i="" have="" this="" code....
="" foomanaged.h
#pragma="" once
using="" namespace="" system;
namespace="" foomanaged
{
public="" __gc="" class="" mfoo
{=""
private:
foo="" *="" _foo;
public:
mfoo();
~mfoo();
void="" manageddosomefoo();
};
="" constructor
mfoo::mfoo()=""
{
_foo="new" foo();
}
="" destructor
mfoo::~mfoo()
{
delete="" _foo;
}
="" mfoo::manageddosomefoo()=""
{
_foo-="">DoSomeFoo();
}
}
the fooManaged.cpp file just has...
#include "stdafx.h"
#include "Unmanagedfoo.h"
#include "fooManaged.h"
#using mscorlib.dll
it all compiles...but there is a big linking error!!
Compiling...
fooManaged.cpp
Linking...
LINK : error LNK2020: unresolved token (0A000005) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000019) free
LINK : error LNK2020: unresolved token (0A00001A) strlen
LINK : error LNK2020: unresolved token (0A00001B) memmove
LINK : error LNK2020: unresolved token (0A00001C) memcpy
LINK : error LNK2020: unresolved token (0A00001D) delete
LINK : fatal error LNK1120: 6 unresolved externals
i must be doing something wrong, some help with this will be very wecome
thanks
|
|
|
|
|
|
i dont know how to do that, so i guessed at added msvcrt.lib to the command line in addional options in the linker properties, but i get even more errors!
|
|
|
|
|
Project's Property Pages dialog box -> Linker->Input. Add msvcrt.lib to the Additional Dependencies.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
thanks man, i've done that but i am stil getting errors when linking, just two though...
Linking...
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(_tolower.obj) : error LNK2001: unresolved external symbol __malloc_dbg
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
C:\Documents and Settings\Major Pigeon\My Documents\Visual Studio Projects\fooManaged\Debug\fooManaged.dll : fatal error LNK1120: 2 unresolved externals
|
|
|
|
|
Ok so I've got my C++/CLI solution, which now includes some old native C files (not C++ files). I don't want these C files to be compiled to managed; I just want to be able to call them from my managed ref classes in my C++/CLI solution. How can I do that? The compiler complains it won't compile .c files with the /clr syntax.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Judah Himango wrote: The compiler complains it won't compile .c files with the /clr syntax.
Yeah, one of "advances" that came with VS2005.
Anyway, try to simply rename the c files to cpp and compile. You may get some compiler errors, but they should not be hard to fix.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: Anyway, try to simply rename the c files to cpp and compile. You may get some compiler errors, but they should not be hard to fix.
Or put the C files into a native DLL and export the required functions out of it.
Regards,
Nish
|
|
|
|
|
Nishant Sivakumar wrote: Or put the C files into a native DLL and export the required functions out of it.
Out of curiosity - would it work with a static lib rather than a dll? I am too lazy to try
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: Out of curiosity - would it work with a static lib rather than a dll? I am too lazy to try
I haven't tried a static lib myself either, but I do remember a few people complaining how that's caused problems for them.
Regards,
Nish
|
|
|
|
|
I'm not a C++ guy by trade, so maybe this is a stupid question, but how do I export the native functions out of it so that my C++/CLI dll can see those functions?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
|
|
Yeah I tried that, several hundred compiler errors. Even if I did get it to compile, wouldn't that be compiled to managed code? I don't need this particular piece of code in managed land...
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I've got a C++/CLI library I'm using to wrap some native C methods in order to call them easily from another .NET language.
This is probably an easy question, but how can I convert a .NET string (System::String) to a LPCSTR? I'm new the the CLI extensions for C++, and google doesn't give me anything other than the old MSDN article which refers to solutions using the old MC++ syntax.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Judah Himango wrote: I've got a C++/CLI library I'm using to wrap some native C methods in order to call them easily from another .NET language.
This is probably an easy question, but how can I convert a .NET string (System::String) to a LPCSTR? I'm new the the CLI extensions for C++, and google doesn't give me anything other than the old MSDN article which refers to solutions using the old MC++ syntax.
Hello Judah,
See http://www.codeproject.com/managedcpp/StringConvertor.asp[^]
If you don't want to use the class, look at the source code to see how it's done.
Regards,
Nish
|
|
|
|
|
|
Hi..I need a sample code or a dll that detect if any hardware connected to parallel port and usb.
karanba
|
|
|
|