problem using enum in another cpp file - c++

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.

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.

How to import and use the CryptProtectData method correctly

I want to encrypt some text in my program using that method.
I included the dpapi.h header file, but I was told that the method was not defined.
How do i fix this?

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.

generating subdocuments with doxygen

I have a large C++ software application documented with doxygen. How can I set it up so that I can generate subdocuments for specific classes? The classes are documented with in-source commenting, their own .dox files, and images/ directory. I need to be able to generate a standalone pdf file specific to a single class.
I can use grouping to identify what will be included in that subdocument, but how do I generate output for a single group?
If you have a specific .dox file per requested output entity, then all you need to do is define in that file as input the files declaring and defining that class.
Say for example you want an output only for class MyClass which is declared in file myclass.hpp and whose implementation is in myclass.cpp, then in myclass.dox, just add this:
INPUT = ./myclass.cpp \
./myclass.hpp
Of course, you can have different paths for .cpp and .hpp. Or you can document more than one class.
Then, run doxygen on that myclass.dox file.
Also watch out for the output folder name. For the html output, the default name is html so you might want to rename it to avoid mixing up all the different outputs. For example, you might want to add in the dox file something like:
HTML_OUTPUT = html_myclass

changing the file name

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.