473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Where do I put the code for managed classes in managed C++

Hey everyone,

I noticed that unlike C#, managed C++ still uses headers and implementation
files. My question is, is there any consensus of where to put the
implementation of the managed class?

In my project, I put everything in the header file. I don't see the need to
put it in a seperate implementation file.

Any thoughts?

Thanks,
--
Tom Tempelaere.
Nov 17 '05 #1
15 1176

"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:29**********************************@microsof t.com...
Hey everyone,

I noticed that unlike C#, managed C++ still uses headers and
implementation
files. My question is, is there any consensus of where to put the
implementation of the managed class?

In my project, I put everything in the header file. I don't see the need
to
put it in a seperate implementation file.

Any thoughts?


It's just a question of style.

Putting all your member definitions in the header file makes them implicitly
inline, but given that most inlining is done by the JIT and happens
regardless of whether the function was marked as inline, it's not clear that
that's really a significant factor.

It's likely the case that putting all the implementation in the header file
will result in slower build times as the project gets larger - that's one
advantage the old header file/implementation file technique still has over
the C#/Java all in one file model.

-cd
Nov 17 '05 #2
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:29**********************************@microsof t.com...
In my project, I put everything in the header file. I don't see the need
to
put it in a seperate implementation file.


It's not something that I use, but I _think_ that WinForms puts code in
headers too. So, if you want a precedent, and one from inside the big house,
there you go. :-)

Now I know that the language allows it, and the distinction between source
and header that was so clear to me in the K&R days is not so black and white
in modern C++, but it looks a tad strange to me. Just my opinion ...

Regards,
Will
Nov 17 '05 #3
Hi Carl,

"Carl Daniel [VC++ MVP]" wrote:
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:29**********************************@microsof t.com...
Hey everyone,

I noticed that unlike C#, managed C++ still uses headers and
implementation
files. My question is, is there any consensus of where to put the
implementation of the managed class?

In my project, I put everything in the header file. I don't see the need
to
put it in a seperate implementation file.

Any thoughts?
It's just a question of style.

Putting all your member definitions in the header file makes them implicitly
inline, but given that most inlining is done by the JIT and happens
regardless of whether the function was marked as inline, it's not clear that
that's really a significant factor.


I see. But, since all methods are exported because it is a library (in my
project it is), I don't think it really matters anymore.
It's likely the case that putting all the implementation in the header file
will result in slower build times as the project gets larger - that's one
advantage the old header file/implementation file technique still has over
the C#/Java all in one file model.


Tom.
Nov 17 '05 #4
Hi William,

"William DePalo [MVP VC++]" wrote:
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:29**********************************@microsof t.com...
In my project, I put everything in the header file. I don't see the need
to
put it in a seperate implementation file.
It's not something that I use, but I _think_ that WinForms puts code in
headers too. So, if you want a precedent, and one from inside the big house,
there you go. :-)


YES! :D
Now I know that the language allows it, and the distinction between source
and header that was so clear to me in the K&R days is not so black and white
in modern C++, but it looks a tad strange to me. Just my opinion ...


Well, since I'm used to coding .NET in C#, I kind of dislike going back to
the header/implementation model. But managed C++ is probably more than just
C# so the model is probably still useful. I think I will be convinced once I
start mixing managed and unmanaged code. This is the actual purpose of my
project in managed C++: use of unmanaged C++-libraries under the hood.

BTW: Do we have a shorter name/tag for managed C++, like MC++ or so?

Thanks,
Tom Tempelaere.
Nov 17 '05 #5

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...

It's not something that I use, but I _think_ that WinForms puts code in
headers too. So, if you want a precedent, and one from inside the big
house, there you go. :-)

Now I know that the language allows it, and the distinction between source
and header that was so clear to me in the K&R days is not so black and
white in modern C++, but it looks a tad strange to me. Just my opinion
...

Regards,
Will


You're correct. That's exactly where the implementing code is placed in a
..NET Windows Form project, much to the displeasure of purists (some of whom
have been very vocal about it).
AAMF, it remains that way in the VS 2005 beta, so it looks not to be a
temporary thing, but possibly a new trend coming from the "big house".

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #6
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:36**********************************@microsof t.com...
BTW: Do we have a shorter name/tag for managed C++, like MC++ or so?


Yes, at least in this group MC++ stands for "Managed Extensions for C++" or
just "managed C++".

That's the good news. The bad news is that the .Net targetting dialect (my
word) of C++ is getting a new name to go with new syntax in VS.Net 2005.
It's short name is usually written as C++/CLI.

Just by the way, at some point in the future C++/CLI will be an ECMA
standardized language and sometime before we all retire <g> it should be
standardized by ISO as well.

Regards,
Will
..
Nov 17 '05 #7
"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:eF*************@TK2MSFTNGP14.phx.gbl...
You're correct. That's exactly where the implementing code is placed in a
.NET Windows Form project, much to the displeasure of purists (some of
whom have been very vocal about it).


Count me in that group. Or in the "dinosaurs" group of people who learned
_the man's_ language from the famous tome by K&R with the white cover and
the big blue C. :-)

Regards,
Will
Nov 17 '05 #8
Peter van der Goes wrote:
You're correct. That's exactly where the implementing code is placed
in a .NET Windows Form project, much to the displeasure of purists
(some of whom have been very vocal about it).
AAMF, it remains that way in the VS 2005 beta, so it looks not to be a
temporary thing, but possibly a new trend coming from the "big house".


Then there is something I don't understand : I believed that part of the
"C++ come back" in VS2005 was due to the fact that MS realized that the
compilation model of C# and VB.NET didn't scale well, and that the
header/implementation separation was still the only way to keep build time
to grow exponentially on large projects. I am totally wrong here?

Arnaud
MVP - VC
Nov 17 '05 #9
> You're correct. That's exactly where the implementing code is placed in a
.NET Windows Form project, much to the displeasure of purists (some of whom
have been very vocal about it).


Nothing prevents you from manually cut and pasting those event handlers
to the .cpp file, though. The form designer will still be working.
However, you might get into trouble in the long run, like if you double
click on an event in the designer. I would certainly prefer if the final
release had the option of putting the event handlers to the .cpp file.
At least it should tolarete if we do that manually.

Tom
Nov 17 '05 #10
Arnaud Debaene wrote:
Peter van der Goes wrote:
You're correct. That's exactly where the implementing code is placed
in a .NET Windows Form project, much to the displeasure of purists
(some of whom have been very vocal about it).
AAMF, it remains that way in the VS 2005 beta, so it looks not to be
a temporary thing, but possibly a new trend coming from the "big
house".


Then there is something I don't understand : I believed that part of
the "C++ come back" in VS2005 was due to the fact that MS realized
that the compilation model of C# and VB.NET didn't scale well, and
that the header/implementation separation was still the only way to
keep build time to grow exponentially on large projects. I am totally
wrong here?


I don't think so.

OTOH, if you're worried about build times, you're probably building
something big. And if you're building something big, you're worried about
having a solid, maintainable design (right?). In which case, your WinForms
classes shouldn't have much "meat" in them - they should just be a GUI
veneer over the real guts of your application (model-view anyone?), so the
bulk of your code can still be implemented in The One True Style of
splitting interface into header files and implementation into implementation
files.

Of course, YMMV - mine always does :)

-cd
Nov 17 '05 #11

Carl Daniel [VC++ MVP] wrote:
Arnaud Debaene wrote:
Peter van der Goes wrote:
You're correct. That's exactly where the implementing code is placed in a .NET Windows Form project, much to the displeasure of purists
(some of whom have been very vocal about it).
AAMF, it remains that way in the VS 2005 beta, so it looks not to be a temporary thing, but possibly a new trend coming from the "big
house".
Then there is something I don't understand : I believed that part of the "C++ come back" in VS2005 was due to the fact that MS realized
that the compilation model of C# and VB.NET didn't scale well, and
that the header/implementation separation was still the only way to
keep build time to grow exponentially on large projects. I am totally wrong here?


I don't think so.

OTOH, if you're worried about build times, you're probably building
something big. And if you're building something big, you're worried

about having a solid, maintainable design (right?). In which case, your WinForms classes shouldn't have much "meat" in them - they should just be a GUI veneer


The problem is not the size of the code in the header : it is in how
many translation units is this header #included and how often it is
changed (and when finishing the GUI, it changes a lot...)

Arnaud
MVP - VC

Nov 17 '05 #12
Tamas Demjen wrote:
I would certainly prefer if the final
release had the option of putting the event handlers to the .cpp file.
At least it should tolarete if we do that manually.


Hi Tom,

This will not be possible for the Whidbey release, the basic
architecture for the designers assumes headerless programming model. For
future releases we are looking into supporting a more traditional (at
least for non template code) C++ model.

Ronald Laeremans
Visual C++ team
Nov 17 '05 #13
Thanks. It's odd, because in both VC++ 2003 and 2005 Beta 1, when I
manually move the InitializeComponent function to the .cpp file, the
designer is still working OK, as far as I can tell. I don't know what
kind of problems we may run into with this in the long run, though. So
it's officially not supported, it's good to know.

Tom
Hi Tom,

This will not be possible for the Whidbey release, the basic
architecture for the designers assumes headerless programming model. For
future releases we are looking into supporting a more traditional (at
least for non template code) C++ model.

Ronald Laeremans
Visual C++ team

Nov 17 '05 #14
I find that in vc++ 2003 having all the implimentation code in the header is
a head ache, if i need to define class A which has a method that uses class B
and Class B has a member of Class A you are dead unless you have
implimentation code file. If ms is not going to change this every thing in
the header desing in Whidbey then the new compiler needs to handle the above
case like c# and vb.net.

"Tamas Demjen" wrote:
Thanks. It's odd, because in both VC++ 2003 and 2005 Beta 1, when I
manually move the InitializeComponent function to the .cpp file, the
designer is still working OK, as far as I can tell. I don't know what
kind of problems we may run into with this in the long run, though. So
it's officially not supported, it's good to know.

Tom
Hi Tom,

This will not be possible for the Whidbey release, the basic
architecture for the designers assumes headerless programming model. For
future releases we are looking into supporting a more traditional (at
least for non template code) C++ model.

Ronald Laeremans
Visual C++ team

Nov 17 '05 #15
Aaron,

I've been trying to figure this one out for a while and I'm stumped. I have
a class which has a member object (child class), but in the child class I
want to access a function from the parent form. When I add the cross
referencing headers I get compile errors. Are you saying that if I split up
the .h and .cpp files I will be able to achieve this? I appreciate any help.
It's driving me crazy. Basically, having a form as a member of another form.
But the smaller child form wants to either call a function in the parent form.

"Aaron Fischer" wrote:
I find that in vc++ 2003 having all the implimentation code in the header is
a head ache, if i need to define class A which has a method that uses class B
and Class B has a member of Class A you are dead unless you have
implimentation code file. If ms is not going to change this every thing in
the header desing in Whidbey then the new compiler needs to handle the above
case like c# and vb.net.

"Tamas Demjen" wrote:
Thanks. It's odd, because in both VC++ 2003 and 2005 Beta 1, when I
manually move the InitializeComponent function to the .cpp file, the
designer is still working OK, as far as I can tell. I don't know what
kind of problems we may run into with this in the long run, though. So
it's officially not supported, it's good to know.

Tom
Hi Tom,

This will not be possible for the Whidbey release, the basic
architecture for the designers assumes headerless programming model. For
future releases we are looking into supporting a more traditional (at
least for non template code) C++ model.

Ronald Laeremans
Visual C++ team

Nov 17 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CodeTyro | last post by:
My native language being C++, I've got a few questions that a couple of hours of searching on msdn didn't answer. First, when using unsafe code and pointers, what is the C# equivalent to the C++...
4
by: 0to60 | last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math computational component. I need the guts of the thing to be in native code, as performance is key for that part. But, I...
2
by: Steven Cool | last post by:
Hi, DA PROBLEM: Once I wrote a c++ dll. I wanted to use that dll in my new c# project, so I compiled it with the CLR option. The compilation was ok. Like I said, I wanted to use the dll (with...
4
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code...
4
by: quortex | last post by:
Hi, I have created a very small test wrapper class in Managed C++ which wraps up some very simple native code. I am using C# 2 + Visual Studio 2005 Beta 2. I have the back end C++ library...
1
by: bonk | last post by:
Hello, I am trying to create a c++ dll or lib (not COM) that contains a little bit of managed code and a lot of unmanged code using c++/CLI. Basically some classes rely on managed bits...
11
by: Peter Oliphant | last post by:
Is there any plan to support templates with managed code in the (near) future? For instance, VS.NET 2005... : )
8
by: Ignazio | last post by:
When creating forms with Visual C++ 2005, all the code for building the interface (the InitializeComponent method) and event handlers are set in the ..H file, as they were inline methods. So I ask,...
8
by: Henri.Chinasque | last post by:
Hi all, I am wondering if there are any quick/efficient ways to look at a piece of c++ code and determine if it would run faster if it was compiled to native code. I ask this because all of my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.