changing the file name - c++

I have copied header and cpp file from one project to another. I need to change the file names now. The header file has the following code that I don't understand. If I change the file name, how should I change this code? Thanks for helping.
#if !defined(AFX_MSELCFLCOMPDLG_H__8687FD1A_777D_4967_A331_42C8536DE2DE__INCLUDED_)
#define AFX_MSELCFLCOMPDLG_H__8687FD1A_777D_4967_A331_42C8536DE2DE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif

That is called an include guard and it prevents the file from being included more than once. You don't need to change it if you change the filename. The long string of digits following the name will be unique enough. If you want to keep the name and the constant in sync change the "MSELCFLCOMPDLG_H" portion to whatever you new file name is.

You don't need to, but you probably should.
This code is there as a header guard. It stops the contents from being included multiple times into a single source file.
Changing it is a matter of maintenance and good practice.

Related

Interaction between multiple files

I need to have two files in my setup. The second file will perform some variable definitions, but based on preprocessor directives read on the first file. The first file will then have to do stuff like set up an object, using the variables defined in the second file as parameters to the constructor.
Is this possible to have this back and forth information between two source files?
To sum up (something like this):
*File1 uses a #define status true.
*File2 sees the preprocessor directive of File1.
If its true it sets up some variables.
*File1 then initializes an object with the variables from File2.
In this example, steps 1 and 3 are redundant. Because if File1 sets up the preprocessor directive, it can know the variables that File2 which is going to set up - by hardcoding means.
But I just want to experiment with what information I can pass back and forth... Can File2 read preprocessor directives from File1? Can then File1 read back information from File2?
EDIT (pseudocode):
//file1.cpp
#define status true
//this class is defined previously
//var1 was defined in file2.cpp
MyObject object1(var1);
//file2.cpp
//status is the preprocessor directive from file1
if (status == true)
{
int var1 = 1;
}
There is absolutely no interaction between preprocessor directives in multiple files.
If you recall, #include is just automated copy/paste. So you can put your directive in a header file, then #include that file into your other files. When you update the directive in the header file it will be like you updated the directive in both files, so they can't get out of sync, but there is still no cross-file interaction.
Officially, a translation unit is a source file after processing all the #includes. Preprocessor directives in one translation unit can't affect any other translation unit.

Macro within a loop and include

In Stata, I'm trying to use the command include to run several regressions in one do file. The overall goal is to help in forecasting Natural Gas production.
I have a do file for each product and basin that I'm interested in. Within each do file I am running several versions of the regression based on data available at specific times (e.g. the first set of regressions is for product type 4, in basin 2, with information available in June 2020).
The regression command within the do file looks something like this:
include "gas\temp\NG var.doh"
foreach time in dec14 dec15 dec16 dec17 previous current {
arima price_`perm4type' `perm4pvars' if tin(,`yq_`time'') , ar(1) ma()
}
I have the perm4pvars defined in the file NG var.doh like this:
local perm4pvars txfreeze PNGHH_`time' d.CPIE_`time' d.IFNRESPUOR_`time' POILWTI_`time'
When I run my do file the time from my doh file doesn't show up. So I get an error message: "PNGHH_ is an ambiguous abbreviation"
How can I get the time to show up in my regress command?
I did try doing this in my .doh file
foreach time in dec14 dec15 dec16 dec17 previous current {
local perm4pvars txfreeze PNGHH_`time' d.CPIE_`time' d.IFNRESPUOR_`time' POILWTI_`time'
}
I got it to run, only for time=current
The relationship between the included .do file and the main .do file is not symmetric.
The point of include is that the included do file is read into the main do file. But the included do file knows nothing about any files it is included in. So definitions in the included do file may not usefully refer to definitions in the main .do file, or to any others, unless they in turn are included, or so I presume.
That explains why your reference to local macro time in the included file doesn't do what you want. It's not illegal in any do file or Stata program to refer to a local macro that doesn't exist (meaning, is not visible from the file) but as here the consequences may not be what you want.
Imo your issue is more basic than what the above answer suggests, in that you want to use locals from a loop outside of it. Or, in the case where you got it to run for time=current, misunderstanding what the loop does. Might be good to get a good understanding of the functioning of loops first, also since you seem to be using multiple other loops that are not detailed in your question and where I can only assume those are specified correctly.
Assuming the gas\temp\NG var.doh file only holds the line defining the local, i.e. local perm4pvars txfreeze PNGHH_`time' d.CPIE_`time' d.IFNRESPUOR_`time' POILWTI_`time', a way to get it working the way you want (or at least how I think you want it, since you do not detail the specifications you want to achieve with your loop) is to move the include inside the loop, changing your code to:
foreach time in dec14 dec15 dec16 dec17 previous current {
include "gas\temp\NG var.doh"
arima price_`perm4type' `perm4pvars' if tin(,`yq_`time'') , ar(1) ma()
}
This way, the line in the included .do file can use the local time from the loop. In the case there is more in the .doh file you would have to change your code a bit more to get it to work, however I can't help you with that unless you give me more information about the structure of the code and what you want to achieve with it.

Change default save file type on Code::Blocks

When Code::Blocks creates a new empty file (Ctrl+Shift+N) it always uses the .c extension. If I want to change the extension to .cpp I have to type that in manually each time.
This is annoying when I forget to add the extension and accidentally create a '.c' file.
Since I am lazy, is there a way for the file type to default to .cpp (or any other type that is wanted)?
I was searching for this stupid solution all day long but unfortunately, nothing was found. It seems to be the default setting need to be changed whenever you want to use any template from any project.
Go to Program Files/CodeBlocks/share/CodeBlocks/templates/wizard/console/cpp
You'll see file main.cpp, what you need is to just edit the contents of this file to your default code and save it.

How to use the original filename in a multi file template in resharper?

I have a multi file template in resharper and I can use $NAME$ macro to get the name of the original file to use to name the other files in the template. But I also want to use the $NAME$ of the original file in the content of the other file template.
Is this possible? I can't see a macro which seems suitable for the internal variables as onlt the Current File Name seems available.
Anyone know if this is possible or how I might workaround this?
As a workaround, you may create a parameter $FILENAME$ (macro "Current file name without extension") in the first file e.g. in the comments, like:
class Foo
{
//$FILENAME$
}
Then you may call this parameter in other files of the multifile template - this parameter will contain the name of the first file since the first file will be generated before other ones.
Unfortunately, there isn't a macro that will give you this. I've added a feature request that you can vote on and track (and more specific detail as to what your requirements are would be useful) - http://youtrack.jetbrains.com/issue/RSRP-415055
It is possible to write your own macros as part of a plugin, but there isn't a sure-fire way of getting the name of the first document in the created file set. The IHotspotSessionContext instance that is passed to the macro via IHotspotSession.Context property includes an enumerable of IDocument, from which you can get IDocument.Moniker, which will be the full path for file based documents. However, there's no guarantee of the order of the enumerable - it's backed by a hashset. You might be able to rely on implementation details (small set, no removes) to be able to use the first document as the original, but there is really no guarantee of this.

problem using enum in another cpp file

Hi I a have created a global.h file in which I define enum Token
I get the garbage value of token if I use the value of Token other than glabal.cpp file
I have also include the "global.h" file in other file where I am using the Token value how can I correct this problem.
If I am correct in assuming that your problem is that you don't want to include global.h in each of your files...
You need to include the enum in any source file you use it from. You cannot forward declare an enum.