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)

View 2 Replies


ADVERTISEMENT

Visual C++ :: Including New Header File

Apr 22, 2013

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 ...

View 3 Replies View Related

C++ :: Including Header Files To Source File?

Jul 10, 2013

For example, I have the below files in a project called Calculate :

Source files : Calculate.cpp , Average.cpp (with out main)
Header files : Calculate.h , Average.h

I knew in general, we have to include Average.h to project header file Calculate.h to make it as part of project.

technical difference between adding header file (Average.h) to either project header file (Calculate.h) or project source file (Calculate.cpp) ?

I found no difference in an output. But, there must be technical difference.

View 3 Replies View Related

C++ :: SIP Parser And Header File Including (using Sofia-sip)

Nov 6, 2012

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:

Code:
#include <iostream>
#include <stdio.h>
#include <sofia-sip/msg.h>
#include <sofia-sip/msg_parser.h>
#include <sofia-sip/msg_mclass.h>
int main() {
char *msg_data = "...";

[Code] ....

When I try to compile the code using

Code:
g++ -o parser -I/usr/include/sofia-sip-1.12 parser.cpp

I get the following failure:

Code:
parser.cpp:10:45: error: "sip_default_mclass" was not declared in this scope ....

View 4 Replies View Related

C++ :: Including Header Files Located In Two Different Directories

Oct 23, 2013

I have these two files:

/project/protocol/guarddog/report.h

/project/protocol/sky/report.h

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 assume just doing this would be ambiguous:

#include "report.h"

View 1 Replies View Related

C++ :: Including Header And Inheritance - Parent And Child Classes

Jan 27, 2012

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....

View 4 Replies View Related

C :: Including Source File Twice But With Include Guard

Jun 14, 2014

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.

Code:

// filename: main.c
#include "source1.c"
#include "source2.c"

[Code]....

View 4 Replies View Related

C++ :: Including Outside Functions Into Classes?

Mar 6, 2015

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.

View 2 Replies View Related

C++ :: Including Cocoa In A Program

May 13, 2013

I am running OS X Lion 10.7.5 and trying to include cocoa.

#include <iostream>
#include <Cocoa/Cocoa.h>
int main(int argc, char** argv) {
std::cout << "Hello, world!" << std::endl;
return 0;
}

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?

View 4 Replies View Related

C/C++ :: Including All Repetitions For One Turn

Feb 22, 2015

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

[Code]....

View 3 Replies View Related

C :: Error Including Undeclared Structure

Aug 11, 2013

I get this error :

stra.c:54:29: error: "PS_index" undeclared (first use in this function)

and the function is

PS_Index = function(PS_index, indexData);

so what i am trying to do is :

first file:

Code:
#include <stdio.h>
#include <stdlib.h>
#include "stra.h"
int main (){
char name[] = "index.pif";
uint32_t i = 0;

[Code] .....

And header file:

Code:
typedef struct StraIndex{
uint32_t s;
uint32_t *i;
uint32_t *t;
}StraIndex; s

So first I would like to create my stra.o so i compile it as :

gcc -c stra.c -o stra.o

and then i get the above error. What would be the proper way to get a global structure inside my object.

View 2 Replies View Related

C++ :: Installing And Using Libraries (And Including Dependencies With Binaries)

Mar 4, 2013

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.)

View 7 Replies View Related

C# :: Including A String In SQL Query For Excel Spreadsheet

Jan 15, 2015

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.

public partial class ExcelAdapter : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("ExcelCSTest.xls") + ";" + "Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"";

[Code] ....

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.

View 1 Replies View Related

Visual C++ :: Linker Error When Including OpenGL

Aug 23, 2014

I have this code in my project

Code:
// OpenGL1.cpp : main project file.
// #include "stdafx.h"
#include "windows.h"
#include <GL/gl.h>

[Code] ....

and I got this error:
Configuration: Debug Win32 ------
1> OpenGL1.cpp
1>LINK : fatal error LNK1104: cannot open file 'C:Program FilesMicrosoft SDKsWindowsv7.0AIncludegl.obj'

Why it wants the gl.obj and how to make this code working without error?

View 3 Replies View Related

C++ :: Including Own Class Instead Of Interior Class?

Aug 21, 2013

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?

View 10 Replies View Related

C++ :: Create User Defined Class And Have Access In Separate Header File From Main

Mar 15, 2013

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:

1> Resistor.cpp
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2
esistor.h(11): error C2146: syntax error : missing ';' before identifier 'resistor'
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2

[Code] .....

Here is the first portion of the .h file:

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>

class CResistor{
double res1, res2, res3, percentage, Nominal, Tolerance;

[Code] ....

View 16 Replies View Related

C :: Head First Google Map Associated With JSON File

Apr 5, 2014

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.

The corresponding files are as follows:

"output.json" Code: data=[
{latitude: 42.363400, longitude: -71.098465, info: 'Speed = 21'},
{latitude: 42.363327, longitude: -71.097588, info: 'Speed = 23'},
{latitude: 42.363255, longitude: -71.096710, info: 'Speed = 17'},
{latitude: 42.363182, longitude: -71.095833, info: 'Speed = 22'},
{latitude: 42.363110, longitude: -71.094955, info: 'Speed = 14'},
{latitude: 42.363037, longitude: -71.094078, info: 'Speed = 16'},

[Code]...

Code:

42.363400,-71.098465,Speed = 21
42.363327,-71.097588,Speed = 23
42.363255,-71.096710,Speed = 17
42.363182,-71.095833,Speed = 22
42.363110,-71.094955,Speed = 14
42.363037,-71.094078,Speed = 16

[Code]...

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.

View 4 Replies View Related

C/C++ :: Using Multiple Files And Includes

Mar 23, 2014

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()

[Code]......

View 1 Replies View Related

C :: Switch Case Character Scanf (also Includes Arrays)

Nov 10, 2014

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();

[Code]....

View 2 Replies View Related

C/C++ :: Writing A Program Which Includes Encoding And Decoding A Message?

Oct 31, 2014

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>.

View 13 Replies View Related

C++ :: Moving The Head Of Array

Mar 19, 2014

Basically, my function receives an array. For example:

u8 array = {1, 2, 3, 4, 5}

I don't need the first 2 elements, how can I access the array's 3rd element as head? I plan to throw the received array to another function.

array = array[2];
somefunc(array);

Will somefunc get index 2 as start of the array?

View 1 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

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;
} }

View 1 Replies View Related

C++ :: Doubly Linked List With Head Node

Oct 17, 2014

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.

//node.h
#pragma once
class Node
{
publi

[Code].....

View 1 Replies View Related

C++ :: Deleting Head Node In Linked List

Sep 8, 2014

I would like my function to return the data that was deleted. I have this code at the moment, where value_type is just an alias for int at the moment:

node::value_type linkedlist::removeFromHead(){
node* temp_head;
node::value_type data;
data = head_ptr->getData();

[Code] .....

When I try to use this function though, I get a segfault.

View 19 Replies View Related

C++ :: Changing Address Value Of Head Node In Linked List

Jan 17, 2014

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.

bool deleteNode(struct node *head, struct node *delptr) {
node *cur = head;
node *tempNextptr= cur;
using namespace std;
while(cur) {
if (cur == delptr)

[Code] ....

View 1 Replies View Related

C++ :: Implementation File Versus Header File - Eclipse Giving Errors

Feb 10, 2013

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?

#include "KeyValuePair.h"
template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()

[Code] .....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved