C/C++ :: Including Main Header File Which Includes The Including Head
Mar 28, 2015
I have a main.h file where I include all the needed things to make my program compile properly, string, vector etc.
And I also have another header file which comntains a class that is used later in the code (globally), I decided to keep it in another file to make it more clear and easier.
I need to include that file in main.h, but I also include main.h from that class header file because it contains some other includes that are required to compile.
Is this a good thing? Or should I keep main.h out of that class header file and include just things required for the class?
I may have complicated it too much, so I'll show an example, what I do now:
// ---- main.h ----
#include <string>
#include <vector>
#include <ctime>
// other includes, these are just examples
#include "MyClass.h" // the separated class header file
[Code] ......
So, from what you can see MyClass.h requires just including the vector, but to avoid repeating myself I include main.h which does that already, but also includes MyClass.h
So, I have two questions:
1. Is it ok to include in that way (including a file that includes the including file)
2. Is it good to include a main header file with all the includes even if I just need one of them, or should I skip including main.h and include just the things my class requires (vector is just an example)
I have the header (and accompanying lib file) in my project folder, I have it in my solution explorer. And I've tried to add it via C++ Directories.. but that doesn't seem to exist anymore, instead it points to a user property sheet, but where to find or access it ...
I am currently developing a small quick'n dirty SIP (Session Initiation Protocol) parser. Its task is to read a file (or command-line argument) with a SIP requst and parse it using the sofia-sip library. It should exit either with "1" on parsing failure or "0" on parsing success.
I have taken the code snipplet from here: [URL] .... resulting in this source code:
I have two report.h files located in two different directories. However the contents of them are different. How can I include the report.h file located in guarddog into the report.h file located in sky?
I have defined to classes : Parent and Child. I have some global variables in a header file named as "var.h". These variables are used in both Parent and child Classes. The source code of these classes are written below:
Parent.h ============================================== #ifndef PARENT_H #define PARENT_H #pragma once #include <stdio.h> class Parent {
[Code] ....
After compiling, the compiler returns a fatal error as follows:
1>Parent.obj : error LNK2005: "int counter" (?counter@@3HA) already defined in Child.obj 1>C:Documents and SettingspishiDesktop estDebug est.exe : fatal error LNK1169: one or more multiply defined symbols found
It says the "counter" is defined multiple times....
I have four source files. The main source file includes two other source files. The two other source files both include the fourth source file. In the fourth source file I have an include guard. Will the code from the fourth source file exist in two locations in the compiled code? Is this something that is compiler dependent? An example of this is shown in the code below.
I have a hpp file with a list of inline finctions like this:
Code: inline int check() { return 1; } inline int check_1() { return 1; }
... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.
When I attempt to compile the above code, I get several thousand errors, mostly "stray ‘@’ in program", coming from the cocoa framework. It compiles and runs correctly if I omit the cocoa include or if I name the file main.mm instead of main.cpp.
I'm pretty sure it's failing because cocoa is written in objective c and I'm reading it as c++ code..how to include an objective c file in a c++ program?
I am trying to include all repetitions for just one turn but I keep getting
00.0 but I want (the one in red) 170.3 0 0.3 180.0 17 0.0 190.3 18 0.0 200.3 19 0.3 210.0 20 0.3 220.0 21 0.0 22 0.0
so basically I call a function that represents just one turn of getting a random number, and then when the player decides he wants to get a random number that is at least 17 and wants to repeat this 3x I have to print out this chart that shows the chances of the player rolling the numbers between 17-22 [how many times does he get 0,17,18,19,20,21,22] this is what I have
cout << "your score: " << (' ') << "chances for that score:" << endl; /* score is the player's total score for the one turn */ int score = 0; int score0 = 0; // 0
I've worked a lot in Java and Perl and now I'm learning C++ and working on a simple e-reader (let's not get into why I'm not just using Kindle or other existing ones). This is for me and a number of friends.
At first my project will be on OS X, then Windows and Linux, and I hope to eventually use it on Android and iOS. I know that the last two will require separate GUIs, but I'm hoping the rest of the code will port easily.
Here's the problem:
I'm using Poppler to read and display PDF files. I started installing it on my iMac and it needs FontConfig, which is turning out to be a difficult install. I would not want to walk others through this or make them have to install Poppler and FontConfig (and any other libraries I find both need).
I thought I could just compile my final binaries using "-static" but I've been reading about how some libraries can't be statically linked or compiled.
Also, since I want to eventually port this to 4 other OSes (and apparently Poppler can work on those target OSes), I don't want to do something now or depend on something that will make it hard or impossible to port to other OSes later.
With that in mind, here are my questions:
1) Why is it some libraries cannot be compiled statically? How do I know if I'm dealing with one of those libraries?
2) Am I right that I could compile this program statically, and the resulting binary would include code from Poppler and FontConfig and other libraries would be included in the resulting executable binary?
3) What do I need to watch for so I can tell if using a particular library will be a problem when I need to port my program to a new OS? (Assuming, of course, that searching shows that library will compile or has been ported to that OS.)
I am displaying data from an Excel Spreadsheet through an ASP.net web form using C#. I would like to run an SQL query on the data, but am having trouble figuring out how to use a string in my query.
Here is the code I am running in my .aspx.cs file. I am also using a .aspx to display the data in a GridView.
Ideally, I would like to add a WHERE clause to my string (string sSQL = "SELECT * FROM [Sheet1$A1:D14]"/> in order to query the current month and display the row of said month from the Excel Spreadsheet.
I have attempted to use a DataAdapter to insert the string into the query, but could not figure out how to conform my code to work with it.
I want to use FREAK(an opencv key-point descriptor library), a source file which exist in opencv or vc++, on the other hand i need to include the same header file to use the other functions, and when i use that source file i get "ambiguity error" how can i select to use that function from my current directory instead of interior function?
I am a beginner with C++, taking a class right now. The lab this week is to create a user defined class and have it accesses in a separate .h header file from the main.
I think I'm finding my way through it, but I'm getting a complie error that makes no sense to me:
This question is from the book Head First C by Griffiths. Starting on p. 110 the book instructs how to develop a JSON file that will be read by the map application on the website: Geo-locater. Starting from a file containing the values of the latitude and longtitude in CSV format a C program is developed to convert it into a JSON file. Up to this point everything worked perfectly although I doubt whether the generated output file conform with the standard of JSON files due to my lack of knowledge. The problems begin after the previous step. First of all, when I try to save the webpage as a whole (from Chrome, Firefox on Ubuntu 12.04.3 32-bit and Windows 7 64-bit) the local copy of the map.html file is useless. When the file is double clicked a white blank page is displayed with no map to be seen. However, when it is saved with the only html file option the map is displayed but the JSON file in the same directory is not read by the program to display the corresponding red markers. What may be the reason behind this and how can I remedy the situation? It has been bugging me a lot these days.
P.S. I have done exactly as told in the book and I am very unfamiliar with JS. Note that I have also asked the same question previously on Stackoverflow.
I am struggling with the concept of having different ccp's and header files. I made a really bad example project for representation, but basically my question is are any of the #includes unnecessary that I have? Technically it functions, but if I am doing it wrong I want to prevent myself from starting bad habits in the future. My code just basically uses strings and sets a name and prints it. My code is really bad, but I wanted to just use includes in such a way for a quick example.
//MAIN.CCP #include "functions.h" using namespace std; int main()
I'm trying to write a code that is read character user 'e' or ' ' space also numbers I mean a number 'e' or space 'e' a number 'e' or space so forth.But i get absurd numbers. The program shows me the added number. If ' ' entered the taking numbers will stop(scanf will stop).
Example input:
e 1 8 7 2 3 6 or e 1 e 8 e 7 e 2 e 3 e 6
Code: #include <stdio.h> #define MAX 10 void addq ( int *, int, int *, int * ) ; void test();
I am writing a porgram which includes encoding and decoding a message.Now I am doing the encoding part.
The goal is to encode a message using similar approach as Caesar Cipher. But instead of alphabets, I am going to use the entire ASCII code of total 128 codes to be the base.
And it is not a simple shifting, it is a rotation. This means if you want to shift 4 units from char <DEL>, it will come back to the first code in ASCII Code which is at dec 0 char <NUL> and starts the shifting again. It won't jump if the limit of ASCII Code is reached.
Here we've got 7 different malls' names and I am going to encode them with a shift n. I think n is free to set, so here I just set it as 5. This is also called the key.
I have written something and I think it should work, but after all it doesn't. And I don't get what is wrong.
Here is my program:
#include <iostream> using namespace std; const int NUMBER_OF_MALLS = 7; const int MALL_NAME_LENGTH = 13; const int NAME_SIZE = MALL_NAME_LENGTH + 1; void encode(int key, char plain[], int length, char encoded[]) { for (int i = 0; i < MALL_NAME_LENGTH; i++)
[code].....
Note that I am not going to use other libraries, just <iostream>.
This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.
Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)
How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?
I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.
Code: for(i = 0; i < strlen(unscrambledWord); i++) { if(unscrambledWord [i] == c) { Stars[i] = c; } }
i am trying to develop a doubly linked list class. I became stuck at a few of the functions as well as the main.cpp file. i have to insert a character sentence "TRICK OR TREAT" spaces included. I am stuck on the display and the listsize functions and im unsure if my insert has the head node in it. The function parameters were given to us and most of this code was given from a single linked list.
I am attempting to change the value of the head node in my list. I thought due to having pointer defined in parameter list I could change the address value of head node. The argument passed is a struct I did not have to use & in argument list to denote address of struct to compiler. This may have something to do with my problem. I did not include all routines called by main program just the deleteNode routine im having problems with.
I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?