*.H or *.Hpp for Your Class Definitions

*.h or *.hpp for your class definitions

Here are a couple of reasons for having different naming of C vs C++ headers:

  • Automatic code formatting, you might have different guidelines for formatting C and C++ code. If the headers are separated by extension you can set your editor to apply the appropriate formatting automatically
  • Naming, I've been on projects where there were libraries written in C and then wrappers had been implemented in C++. Since the headers usually had similar names, i.e. Feature.h vs Feature.hpp, they were easy to tell apart.
  • Inclusion, maybe your project has more appropriate versions available written in C++ but you are using the C version (see above point). If headers are named after the language they are implemented in you can easily spot all the C-headers and check for C++ versions.

Remember, C is not C++ and it can be very dangerous to mix and match unless you know what you are doing. Naming your sources appropriately helps you tell the languages apart.

Passing master page form data to another webform

In order to pass the values of the control "txtSearch", when Server.Transfer is executed, you could do many things, including passing it via a querystring variable or setting up a session variable, and then check either of those in the Page_Load event of Search.aspx, and if it's populated, call the event that is fired when the user would hit the submit button on the Search.aspx page.

Also, if the Search.aspx file is using the same masterpage, then you can use this.Master.FindControl("txtSearch") to get the control (it you look a the source of the file after it is generated in the browser, you'll notice that controls in the master page aren't really called by their ID, rather that have something appended to them (i.e. it would now possibly be called "ctl00_txtSearch")

Why would a .hpp file be included in a .h file?

Your teacher wants you to implement a template class. The thing about templates is that they need to get instantiated with the correct template type, which means that you can't create the binary before you know what type its gonna be. That is why the implementation is usually written inside the header file. Have a look f.e. here...

If you are new to templates, just ask uncle google or ant wiki ;)

ADD:

To put it simply... when you have something in foo.cpp, it gets translated to binary and the corresponding header foo.hpp serves as a reference to what functions are there in the binary that I could use from my other code. The important thing is that this binary does not (really) change anymore.

On the other hand templates can't be transformed into the binary, until you know what type it is going to be operating on... If you use the template class once with int and another time with vector<double> for template parameter, the resulting binary could be very very different... Therefore you can only compile the code into the binary once you know the type, and therefore you need to pass along the code (inside the header) instead of just function prototypes...

Hope this is clear. It is after all almost 3 o'clock in the morning here.

If not, this should be very comprehensive.

Is it safe to separate your templated class' declaration and definitions on different header files?

This is indeed a better approach because it makes your code look simple and better. Moreover, it is the main reason why header file is used.
Your main header file will simply tell that what functions/classes are you using and without even viewing your code, anyone can guess if you are working correctly or not.
There wont be any safety issues at all.

C++ templates declare in .h, define in .hpp

Typically (in my experience, YMMV) an hpp file is an #include-ed CPP file. This is done in order to break the code up in to two physical files, a primary include and an implementation-details file that the users of your library don't need to know about. It is done like this:

super_lib.h (the only file your clients need to #include)

template<...> class MyGizmo
{
public:
void my_fancy_function();
};

#include "super_lib_implementation.hpp"

super_lib_implementation.hpp (your clients do not #include this directly)

template<...> void MyGizmo<...>::my_fancy_function()
{
// magic happens
}


Related Topics



Leave a reply



Submit