C++ :: Accessing Variables From Other Files

Sep 26, 2014

I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.

Code: //header.h
namespace test {
int arr[5];

[Code] ....

Also tried putting int arr[5] in a Test class within test.h.

I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.

View 2 Replies


ADVERTISEMENT

C++ :: Accessing Variables Of Another Class?

Aug 3, 2013

I've been attempting to create a game with curses and I keep running into the problem of scope. I want to change or use variables of a different class in a different header file. But I don't know if I should use pointers, references or neither. Should I be programming in a manner that doesn't make it necessary to use variables outside of their class?

View 1 Replies View Related

C++ :: Accessing Variables From Another Project

Apr 4, 2013

I have a Visual C++ solution file that contains 3 projects. i want to access the variables declared in a function in a project from a function in another project. Function declarations are in .h file and expansion in .cpp files. Can i use friend class or any other suitable method.

View 6 Replies View Related

C++ :: Accessing Private Variables In Structures

Apr 18, 2013

I need to translate a C program to C by making variables in structures private(no classes yet!) and putting public inline functions. There's a good chance that I have much more problems with my code than I'm asking right now, but I have 4 spots that I'm currently stuck in and can't access properly.

My structures:

Code: struct Container
{
private:
int count;
char** lines;
int nlines;

[Code] .....

View 4 Replies View Related

C++ :: Accessing Class Variables In Main

Apr 16, 2014

I am not able to access the class variable noof_vertex in the function merge , the error is the variable is private . below is the code :

#include <iostream>
#include <ctime>
#include <cstdlib>

[Code]....

View 1 Replies View Related

C++ :: Accessing Classes Member Variables Nested Inside Another Class

Feb 22, 2013

I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...

class Package{
public:
Person Sender;
Person Reciever;
int weight;
double cost;
friend ostream &operator<<(ostream &out, Package &pack);

[Code] .....

So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?

View 2 Replies View Related

C :: Accessing Pointers From Other Source Files

Oct 16, 2013

I've recently been learning GTK (though this question is not specific to GTK), and came across a situation that I was unsure how to best handle. Essentially, I've defined several pointers in one source file, and I want to access those pointers from other source files.

The structure of my GTK programs generally follow this pattern:

- "main.c": Define the main window and run GTK main
- "create_window.c": Create and arrange widget pointers in the main window
- "program_functions.c": All other source code for the project (several source files in reality)

In "create_window.c", I declare and define all my widget pointers (e.g. label). If I need to modify those widgets in "program_functions.c" for any reason (say, to change the value of a label), I need access to the pointers created in "create_window.c".

My first thought was to create a global struct of pointers in "create_window.c", and extern that struct to the other source files that need access to the pointers. The thing I don't like about this approach is spreading globals across my program.

My second idea was to create access functions in "create_window.c" where the necessary pointers are statically stored. The first time I call this function (immediately after creating a widget), a static copy of that pointer is stored in the function. Each time afterwards when I call that function (from other source files), I simply use that static pointer to access the widget of interest.

Example:
Code: void edit_label_1(GtkWidget *label_set, const char *string)
{
static GtkWidget *label = NULL;

[Code].....

Are either one of the approaches considered acceptable by standard practice?

View 2 Replies View Related

C :: Accessing Files From Multiple Processors

Apr 9, 2013

I have a big un-editable program, A, which I need to run for like a 1000 different input files. It takes about 15 minutes for each file, so a little parallelisation wouldn't hurt.

I have installed openmpi and it works fine. I have made a small program, B, which selects an input file, moves it to another directory, calls program A with the path to the selected input file and then - when A is done - selects a new input file etc. It should loop until there are no more files in the initial directory.

The problem is this: When I have several processors they might pick the same file and that leads to errors. I have a working program, but it is not pretty.

Code:

#include <stdio.h>
#include <mpi.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int num_procs, procs_id, i, exit;
struct dirent *ent;

[Code]...

Every time a processor tries to move a file that another processor has just moved, the output shows an error message before looping to the next file and trying again. It works, but it is a bit annoying. So my questions are:

1) Can I switch off the error message somehow?

2) Is there a better way to do this?

View 3 Replies View Related

C/C++ :: Creating And Accessing Index Files?

Oct 27, 2014

I'm supposed to read in a data file with fixed length records and fields, create a sorted index list in memory, and save that list to a file. Then I'm to write a second program that interactively (via the Linux command line) takes a key and the index file name, opens and loads the index file, searches for the given key using the index table, and opens and returns the correct data record.

The original file consists of a list of records with a key (int), a name (string of 8 characters max), a code (int) and a cost (double).

The RRN (relative record number) begins at 1, with the RRN at 0 representing a dummy record with only the size in the first entry.

Here is the data file I will be using.

8 blank 0 0.0
12345 Item06 45 14.2
12434 Item04 21 17.3
12382 Item09 62 41.37

[Code]....

The "File is Open" part will be replaced once I figure out what do do once the file is open, just used this message to verify that it was opening the file.

View 12 Replies View Related

C++ :: Global Variables For Multiple CPP Files

Jan 19, 2014

I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:

const int variable_Name = 5;

And the cpp file:

#include <iostream>
using namespace std;
#include "vars.h"
int main ( ) {
cout << variable_Name<< endl;
system ("pause");
return 0;
}

Is there a better way to do this and to make the variables able to be changed within the cpp files.

View 7 Replies View Related

C++ :: How To Share Variables Between Two Header Files

Mar 16, 2012

Here is what I did,

Code:
// A.h
const int salary = 1000000;

// B.h
extern const int salary = 1000000;

But I still got multi-definition errors. How should I fix it?

View 6 Replies View Related

C++ :: How To Change Private Variables In Header Files

Oct 28, 2014

How would I change the private variables in the header files and the code in the cpp files for the primary indexes so they use a dynamic array or vector instead. For the primary index, the initial vector size will be 8.

header

#ifndef MY_PRIMARY_INDEX_H
#define MY_PRIMARY_INDEX_H
#include
#include
#include
#include

class PrimaryIndex

[Code] ....

View 3 Replies View Related

C :: Program To Hide Files Behind Other Files Using Alternate Data Streams

Apr 5, 2013

I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.

The program is as follows:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);

[Code]...

The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?

View 4 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ :: Accessing Value Of Map When It Is A Vector

Jan 30, 2013

I have the following map: myMap<string,vector<int>>. I now want to look through my map to see if a key exists and if it does, retrieve one of the int values from within that vector. What would be the best way to do this? Right now I have the following:

What would be the best way to look for a key and get one of the int values from its vector value? Right now I'm doing something like this:

[code]
map<string,vector<unsigned int>>::iterator it;
it = wordMap.find(someWord);
if(it == wordMap.end){
cout << "No matching entry";
} else{
// this is where I'd want to access the value (the vector) of the map
}

Is there a better way to do this?

View 2 Replies View Related

C++ :: Accessing Setter Methods

Nov 21, 2013

How to i access setter from within a setter?

I know that getter methods can be access like

Code: getAccounts().getAccountNumber();

// for example but for setters how do i do it? this doesnt seem to work though

Code: setAccounts().setAccountNumber(accountNumber);

View 7 Replies View Related

C :: Accessing Variable From Other Class

Feb 19, 2013

Here is the link for my program, I want to access the average value which is located in grade.c (calculate_grade) class through driver.c (main function) but I don't know how to make "average" visible

[URL] .....

View 1 Replies View Related

C :: Accessing Arrays Using Pointers

Aug 30, 2013

I came across the below code snippet in a project and was not sure how value of variable "response" is computed. Here as we can see, pic_data holds two one dimensional arrays but "response" access both the single dimensional array as two dimensional array.

Code:

#define MAX 100
#define MAXBUF 100
u32 response;
u32 index;
}

[code]....

View 3 Replies View Related

C++ :: Accessing Objects Within Another Object

Feb 8, 2014

I'm currently trying to access a variable contained within a base object from another completely different object and I continually get error messages. I'll attempt to put up the important code since it's contained within fairly large classes. From the Base .cpp file. ObjectPosition:

void ObjectPosition::init(float x,float y, float speed, int boundx, int boundy, float hit, int lives, bool live) {
ObjectPosition::x = x;
ObjectPosition::y = y;
ObjectPosition::speed = speed;
ObjectPosition::boundx = boundx;
ObjectPosition::boundy = boundy;
ObjectPosition::hit = hit;
ObjectPosition::lives = lives;
ObjectPosition::live = live;
}

This is the initialization function for the BaseObject. All objects are inheriting these variables which are Protected within the ObjectPosition class.Then they are initialized within the Pig class thus wise:

void Pig::binit(float sx,float sy, ALLEGRO_BITMAP *simage) {
//Sets all ObjectPosition Variables
ObjectPosition::init(800,900,10,80,40,40,10,true);
smaxFrame = 4;
scurFrame = 0;

[code]...

I tried to initialize the boundx through the pig via pinitx but I get errors and I can't access through the pig to the object position to the boundx.

View 10 Replies View Related

C/C++ :: Accessing Private Arrays?

Aug 31, 2014

How do i access the private array? I tried this and it's not working. Want i want to do is create class object in main and pass the string to constructor, and set m_make, m_model to that string. Then call the member function to output that.

const int BUFLEN = 256;
// class declaration
class CVehicle
{

[Code].....

View 2 Replies View Related

C/C++ :: Accessing Private Class?

Apr 4, 2014

I am trying to access the private member from main . The code is as follow. I wanted to call below function from main.

uint16_t Modbus::calcCRC(uint8_t u8length)
#define MAX_BUFFER 64
typedef struct {

[Code]....

View 1 Replies View Related

C/C++ :: Accessing Elements From Arrays

Feb 9, 2014

I'm confused about accessing elements from arrays. Supposed I have an array of pointers to char:

char *names = { "John", "Rose", "Steven" };

To access one of the strings, should I use names[ 0 ][ i ], where i is an index in the set ( 0, 1, 2 ), or should I use names[ i ]? I would think it would be the first option, because this array has 1 dimension that contains others arrays, right?

View 8 Replies View Related

C++ :: Accessing Data Outside A Function

Feb 11, 2013

I was wondering what the best way was to access data outside the function it was created in. I have the user input a data in a custom namespace function, and now im trying to access all those data points in a different function.

View 9 Replies View Related

C++ :: Accessing A Table By Container

Jun 30, 2014

I need a "meaningful" way of accessing a table, the column is representing Err magnitude, and the row is representing Rate magnitude. For each error magnitude and rate magnitude, i define an action magnitude, which is the contains of the table. For example,

Code:
int matrix[10][10];
int Action1 = matrix[0][0];
int Action2 = matrix[0][1];

However, i need a better way of getting matrix[0][0], row and col itself is meaningless. I want to access the table like

"Action magnitude" = matrix["Rate magnitude 1"]["Err magnitude 2"]; using a string instead of int id.

How to easily do this in c++ container?

View 4 Replies View Related

C++ :: Accessing Elements Of Array Dynamically

Jul 26, 2014

I want to access the elements of my array dynamically. So far I've only figured out how to do this manually. if I tried it like this my code would work but there should be a better way right?

View 10 Replies View Related

C :: Segmentation Fault When Accessing Array

Aug 27, 2014

Write a program that reads in the names and the ages of ten people. Store these data in two arrays (make sure that the entered names are not longer than the array size you choose). Then produce a table of ten lines, with each line giving the name and age of a person along with the (positive or negative) deviation of that person's age from the average age. The code I wrote to fill in the arrays looks as follows

Code:
#include<stdlib.h>
#include<stdio.h>
int main()
{ // begin main()
// array length

[Code]....

When I compile it, it gives me warnings that few of the variables I declared aren't used, but that is not affecting the program at all. When I run the program, it allows me to pass the names and ages into the arrays, but when it comes to displaying them, I'm getting a 'Segmentation fault'. I used very similar code in Java to write the program, and it worked fine so what is the problem with C then?

View 8 Replies View Related







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