S
Sean Quinn
Recently I've come across an oddity in .NET, going back to a Managed
C++ implementation for GUIs since I never really learned how to code in
MFC.
Any way, I attempted to put some standard code I often re-use (like my
own random function) in its own namespace, lets call this namespace
"PersonalStd", and noticed that when I tried to reference the function
`random()' in the PersonalStd namespace from the project namespace it
was giving me a LNK2001 error despite everything being included in the
project.
It works fine with namespaces when compiled in unmanaged C++ compilers,
like MSVC6, unfortunately I haven't had a chance to test it on Linux
compilers, but I'm pretty certain it would work fine on those as well.
I think its a conflict with how managed C++ in .NET deals with
additional namespaces, because because when I took the PersonalStd
namespace out of the code, everything worked fine. I'm just wondering
if anyone else has run into this, or if anyone has insight or
suggestions into this?
Oh and as a side note; if anyone knows some really good MFC resources,
tutorials, or books, please let me know -- its sort of been something
that has been eluding me for a few years now that I just never really
tried to learn, but I feel like I should.
An example of what the code looked like with the namespaces is here:
--- PersonalStd.h
#pragma once
#ifndef PERSONAL_STANDARD
#define PERSONAL_STANDARD 1
namespace PersonalStd
{
int random(int, int);
}
#endif
--- PersonalStd.cpp
#include <algorithms>
#include <cmath>
#include "PersonalStd.h"
int random(int l, int h)
{
....
}
--- MainCode.h (where all the functions are in managed C++)
....
System::Void SomeFunction(...)
{
txtBox1->Text = PersonalStd::random(1,10);
}
C++ implementation for GUIs since I never really learned how to code in
MFC.
Any way, I attempted to put some standard code I often re-use (like my
own random function) in its own namespace, lets call this namespace
"PersonalStd", and noticed that when I tried to reference the function
`random()' in the PersonalStd namespace from the project namespace it
was giving me a LNK2001 error despite everything being included in the
project.
It works fine with namespaces when compiled in unmanaged C++ compilers,
like MSVC6, unfortunately I haven't had a chance to test it on Linux
compilers, but I'm pretty certain it would work fine on those as well.
I think its a conflict with how managed C++ in .NET deals with
additional namespaces, because because when I took the PersonalStd
namespace out of the code, everything worked fine. I'm just wondering
if anyone else has run into this, or if anyone has insight or
suggestions into this?
Oh and as a side note; if anyone knows some really good MFC resources,
tutorials, or books, please let me know -- its sort of been something
that has been eluding me for a few years now that I just never really
tried to learn, but I feel like I should.
An example of what the code looked like with the namespaces is here:
--- PersonalStd.h
#pragma once
#ifndef PERSONAL_STANDARD
#define PERSONAL_STANDARD 1
namespace PersonalStd
{
int random(int, int);
}
#endif
--- PersonalStd.cpp
#include <algorithms>
#include <cmath>
#include "PersonalStd.h"
int random(int l, int h)
{
....
}
--- MainCode.h (where all the functions are in managed C++)
....
System::Void SomeFunction(...)
{
txtBox1->Text = PersonalStd::random(1,10);
}