Visual Studio.NET C++ 2005 Express, functions defined in cpp file cause "is not class or na

Hello all,
I am not sure if this is the correct group for this question, but I couldn't find a more appropriate one.
I have Visual Studio.NET C++ 2005 Beta 2 installed and I was trying my hand at creating a simple Windows application. I have a main form that I used the desinger to create with splitContainer. The top container I want to swap out forms depending upon the user selection.
I create a class that inherts from System::Windows::Forms:Form. I used the designer again to create the controls, but which are declared in the header file. The namespace is SDUDataLogger and the class is declared as the following in the header file
namespace SDUDataLogger
{
public ref class frmRunTimeDataLog:: public
System::Windows::Forms::Form
public:
frmRunTimeDataLog(void);
// A ton of other code removed to just focus on ctor
}
I wanted to implement all the functions in a cpp file as I don't like the idea of have all the implementation in the header file. So I create a cpp file called frmRunTimeDataLog.cpp which looks like ( I just copied what was in the header file to the new cpp file and made the function declaration in header file as a prototype.
namespace SDUDataLogger
{
#include "StdAfx.h"
#include "frmRunTimeDataLog.h"
frmRunTimeDataLog::frmRunTimeDataLog(void)
{
frmRunTimeDataLog::InitializeComponent();
//
//TODO: Add the constructor code here
//
}
}
When I compile the cpp file I get the following errors...
.\frmRunTimeDataLog.cpp(17) : error C2653: 'frmRunTimeDataLog' : is not a class or namespace name
.\frmRunTimeDataLog.cpp(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\frmRunTimeDataLog.cpp(19) : error C3861: 'InitializeComponent': identifier not found
.\frmRunTimeDataLog.cpp(23) : warning C4508: 'frmRunTimeDataLog' : function should return a value; 'void' return type assumed
.\frmRunTimeDataLog.cpp(25) : error C2059: syntax error : '}'
.\frmRunTimeDataLog.cpp(25) : error C2143: syntax error : missing ';' before '}'
.\frmRunTimeDataLog.cpp(25) : error C2059: syntax error : '}'

I changed the code around a little and now have the following in the cpp file...
#include "StdAfx.h"
#include "frmRunTimeDataLog.h"
SDUDataLogger::frmRunTimeDataLog::frmRunTimeDataLog(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
but now I get a linker error... it seems I can't win... what is the correct way to declare this and get it to link correctly.. I suppose I could put everything in the header file, but that just doesn't seem like good form...
SDU Data Logger.obj : error LNK2020: unresolved token (06000001) SDUDataLogger.SDUDataLogger.frmRunTimeDataLog::.ctor
C:\Development\Projects\SDU Data Logger\Debug\SDU Data Logger.exe : fatal error LNK1120: 1 unresolved externals

Also, once I get the code to compile and link correctly, how do I get the frmRunTimeDataLog form to be a child of one of the panels contained in the splitContainer? Would it be like
this->runTimeDataLogWindow-> = splitContainer1->Panel1;
For the frmRunTimeDataLog form I configured it so it does not have a title bar or any buttons that would appear on the title bar. Perhaps within Visual Studio C++ Express 2005 a form can't be a child of a panel? I don't know...
Mark

[3524 byte] By [mrhicks] at [2008-2-11]
# 1

Mark: in C++ you should almost never place a #include inside of a namespace: especially if the file you are including itself defines a namespace. You can end up in situations like the following:

// file: a.h
namespace N {
class X {
public:
X();
};
}

// file: a.cpp
namespace N {
#include "a.h"

X::X()
{
}
}

If you preprocessed this code you would see that it expands to:

namespace N {
namespace N {
class X {
public:
X();
};
}

X::X()
{
}
}

Which is definitely not what you want.

Your second example should work: are you sure you are linking in the *.obj file produced? You should try linking with /verbose to see exactly what the linker is doing.

JonathanCaves at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2
Jonathan,
Thanks for info and it has helped my cause. Placing the header file within the namespace was also causing my linker problem as I was placing the same frmRunTimeDataLog.h header file with the namespace of the main form. Once I moved all the header files outside the namespace declaration it appears to be working much better. Thanks A LOT!!
Now I have to figure out how to bind a form to the splitContainer.Panel control. Is this possible? When I do it causes a runtime exception of "Additional information: Top-level control cannot be added to a control.". In order for this to work what class should I inhert from? I want to have multiple forms displayed within the panel depending upon the user's selection.
Mark
mrhicks at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3
Hello,
Okay, I cheated a little here. After I placed all the controls on the form the way I wanted them I then changed the inhertance of the form from
public ref class frmRunTimeDataLog : public System::Windows::Forms::Form
to
public ref class frmRunTimeDataLog : public System::Windows::Forms::Panel
Of course now it doesn't display correctly in the form designer. I compiled it and let it complain about specific properties that were only applicatible to System::Windows::Forms::Form, then it compiled fine. I ran the program and now it shows the frmRunTimeDataLog panel within the splitContainer1.Panel1 now.. Cool, but it would be nice if I could modify the controls on the panel within the form designer as you can with C# or VB.NET. It takes a little while as I use to developing C programs for embedded systems. Different mind set...
Mark
mrhicks at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...