473,320 Members | 1,820 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,320 software developers and data experts.

Body of a function in a header

My program is heavily template based, and I use the VC++, so I have to keep
the templates in the header file. My .cpp files are quite empty (they are
more a connection between header files). Now, my "problem" is that I can't
put the body of classless functions in the header files. I normally "solve"
this problem using the "inline" keyword (inline functions must be in header
files, but the compiler doesn't have to "inline" inline functions). Is there
a better way to do it? (yes... I know... this is an estetical problem :-) )

Can someone tell me why a class can have the body of the methods "inline" in
the header while a classless function can't? Are there istorical reasons?

--- bye
Jul 22 '05 #1
1 2669
"Massimiliano Alberti" <xa*****@geocities.com> wrote...
My program is heavily template based, and I use the VC++, so I have to keep the templates in the header file. My .cpp files are quite empty (they are
more a connection between header files).
This last statement (in parentheses) sounds like a bad idea to me. If your
headers have to be included in a certain order or in order to work some of
your headers require a translation unit to include other headers, it's bad.
If you need something in a header, include the other header in that header.
Now, my "problem" is that I can't
put the body of classless functions in the header files. I normally "solve" this problem using the "inline" keyword (inline functions must be in header files, but the compiler doesn't have to "inline" inline functions). Is there a better way to do it? (yes... I know... this is an estetical problem :-) )
Can someone tell me why a class can have the body of the methods "inline" in the header while a classless function can't?
Nonsense. You may declare any function 'inline' as long as you provide the
function body right there for the compiler to use.
Are there istorical reasons?


I think you're a bit confused there.

inline void foo() { } // doesn't matter where you put this

int main() {
foo();
}

Victor
Jul 22 '05 #2

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

Similar topics

3
by: Kevin Frey | last post by:
Hello, Let's say I have the following: template< class T > class MyClass { void Func( ); }; and I want to declare a specialisation for Func( ) in the presence of
6
by: Sentinel | last post by:
how can i place a script in body (it must be ran automaticly when html interpreter reaches it) that will redirect to another page? what i am doing is checking in php if login is successful...
9
by: bmgz | last post by:
I need to execute a JavaScript function "onload". The only problem is I don not have access to the <body> tag as it is a part of the standard page-header include (a separate file). How could I have...
11
by: Matt Kruse | last post by:
This is a common requirement - "freeze panes" in a table, so that some header rows and some columns on the left are frozen while the body content scrolls. This makes large tables more usable on...
5
by: 2291980 | last post by:
Hello can any body tell me the dff between function redirect($url) { echo "<script>"; echo "window.location='".$url."'"; echo "</script>";
0
by: Spam Catcher | last post by:
Hi all, The client is sending a SOAP body with the following information: <soap:Body> <MyFunction xmlns="http://mycompany/services/t1"> <header> ... Custom Elements Here </header>
2
by: urbanedge | last post by:
I've just acquired a site and uploaded to godaddy and the email function won't work. I'm new to php and I'm not able to determine where the issue is. I've commented out $this->header .=...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.