C/C++ :: Setting Signal Handler - How To Access Class Member

Dec 4, 2014

I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem. My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members. I understand that compiler should know that this class instances will exist during all program execution. I have tried to set static member class Foo instance in another class , but this didn't solve the problem. How to correctly implement signal handling in such case.

Here is example of my code

class MyContainer {
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: How To Access Class Member And Methods From Static Method (signal Handler)

Dec 4, 2014

I am writing my program on C++ language. I have one promblem. I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem.

My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members.

I understand that compiler should know that this class instances will exist during all program execution.

I have tried to set static member class Foo instance in another class , but this didn't solve the problem.

What is correct approach to do this. How to correctly implement signal handling in such case.

Here is example of my code

Code:
class MyContainer{
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] .....

View 4 Replies View Related

C++ :: Cannot Access Private Member Declared In One Class But Can In Another Class

Sep 4, 2014

So I have an ImageManager class, Board class, and Box class. In Board.h I can declare ImageManager imgr; and in Board's constructor I can use imgr and its functions and such. However, in Box.h when I try and declare ImageManager imgr; I get the error "cannot access member declared in class ImageManager". Both declarations are under private, and exactly the same, but one doesn't work. Also, is there a way to only have one instance of ImageManager?

View 19 Replies View Related

C++ :: How To Access Pointer To Class Member

Jan 10, 2015

I have the following scenario :

Code:
class test {
public :
int num;
};
int main() {
test t1;
test *ptr = &t1;
int test :: *mem_ptr = &test::num;
}

I need to access mem_ptr (pointer to a class member) through :

a. object (t1)

b. pointer to the object (ptr).

How can i do that ?

View 4 Replies View Related

C++ :: Access To Private Member Map Outside Class

Oct 24, 2013

This question is more from a design point-of-view rather than coding it to be a fully functional.

So here it goes:

I have multiple files which each require their own object of same class type (ref. First Class). File contents are read from a file to a unordered_map<std::string, std::vector<std::string>> which is either private or protected member inside First Class. First Class does not need any public functions to add, remove or change the data during runtime, but changes are only being made by checking if the file size has changed during the day, if the size is not equal to the last check, map gets updated.

Now, I have a Second Class which is a data handler class. It has public member functions with arguments that needs to be get from First Class's unordered_map using const_iterator. Which way to go with design and implementation.

I know there's two methods to do this. Re-doing handler class is also not out of the question. These two methods I'm aware of are:

1. Declare these maps to local scope, build few global functions and here we go. (Probably the easiest way.)

2. Create public member functions to a First Class which either return a pointer or a reference to a protected/private member. (I'm under the impression that I really shouldn't be doing this because of a bad coding practice.)

Note that I don't need any code here, just some other point-of-views regarding the subject itself for learning better coding practices.

View 5 Replies View Related

C++ :: Class Data Member Access?

Jul 5, 2013

I have some doubt regarding class data member accessing in another file.Follwing code showing error.

class A://file a.cpp
{
public:
int add;
int sub;
};
//file b.cpp
extern class A
void cal()
{
A::add=A::sub;
}

View 4 Replies View Related

C++ :: Cannot Access Private Member Declared In Class

Aug 22, 2013

I have a method:

int filetodb(std::wstring szwf, SQLHANDLESTR *h);

I want to use it, in a thread.

std says, use thread, as:

std::thread second (bar,0); // spawn new thread that calls bar(0)

How can I do this, for my method, that uses more than one, i.e., two, parameters?

My code is:

std::thread thread = std::thread(filetodb, filesP->at(i), h);

compiler says:

Error10error C2248: 'std::thread::thread' : cannot access private member declared in class 'std::thread'c:program files (x86)microsoft visual studio 11.0vcincludexmemory06061ConsoleApplicationa

How, can I do this?

View 2 Replies View Related

C/C++ :: Limit Access To Class Member Functions

Feb 28, 2014

Suppose I make a class, something like having the constructor being invoked first makes sense, I don't have a problem with that. But, how could I limit access to functions until certain functions are called? Perhaps this isn't built into the language so you can't. And maybe this problem never comes up. For example if you have a set() and get() functions, if they are both public functions, there doesn't seem to be a way for the compiler at least now if set() never gets called you shouldn't call get(). I just see this as error prone if you need to use libraries, you have to know not to do it from documentation instead of something the compiler can check.

View 11 Replies View Related

C++ :: Boost Threading - Cannot Access Private Member Declared In Class

Feb 25, 2013

When I put boost::thread Thread; in my struct I get the error error C2248: 'boost::thread::thread' : cannot access private member declared in class 'boost::thread'

The whole struct is

struct Player {
bool key[256];
char nameString[64];
bool lMouseButton;
bool rMouseButton;
double mouseX;
double mouseY;

[Code] ....

View 1 Replies View Related

C++ ::  How To Access A Specific Protected Inherited Member Depending On Class

Dec 30, 2013

I have `MainShop`(base class) then `SwordShop` and `BowShop`(derived classes) and another derived class called `Inventory`. I have a vector under protected in my base class, and when I access it from my derived classes it's okay, but each one has its own value. How can I set them all to have the same value?

//MainShop.h
#pragma once
class MainShop {
private:
//some variables
protected:
vector <string> WeaponInventory;

[code]......

Here every time I run it, it goes straight to the `else` and it displays that I do not have any items. I want to just have one vector for both my bow and Sword shops because vectors take up a lot of memory and my teacher said keep them to a minimum. So I just want one vector that takes in items from my bow class as well as my sword class, but for some reason it's acting as if I have multiple vectors, each with its own set of items.

View 3 Replies View Related

C++ :: Cannot Access Private Member Declared In Class (header File)

Apr 1, 2014

I am currently doing the assignment about linked list. Here are some details information about what I am doing.. This program is C++ and should run on Visual Studio 2010. And it contains three file, two datastructure header and one main cpp file.

This program is trying to arrange and show some sports records. The main program which contain the functions such as reading the result text file(each result text file contain several records of athletes), removing a file, arranging the totalresult and printing it out. And the main program is already given and I cannot overwrite it.

But when I finished and try to build the solution and run it, I am not able to run the program and it give me somethings like these...

warning C4172: returning address of local variable or temporary
error C2248: 'Datastructure1::Datastructure1' : cannot access private member declared in class 'Datastructure1'
see declaration of 'Datastructure1::Datastructure1'
see declaration of 'Datastructure1'
This diagnostic occurred in the compiler generated function 'Result::Result(const Result &)'

And I have tried to comment each function part of the header file and see if can run or not. But I still fail to do so. Here are my codes...

#ifndef DATASTRUCTURE1_H
#define DATASTRUCTURE1_H
class Datastructure1 {
Public:
Datastructure1( );

[Code] ....

There are two header files and look quite long. They are all some linked list functions . I have read and learn linked list data structure before I complete this programs. However, when I complete the functions required, the function cannot be compile....

View 11 Replies View Related

C++ :: Access Private Data Of Base Class Without Access Modifier

Sep 9, 2013

if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example

class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};

how i can acces the a of base class A in derived class B without acces modifiers.

View 16 Replies View Related

Visual C++ :: Access Member Function From Non-member Function In Same CPP File?

Dec 16, 2012

In my MFC, CMyPorpertyPageDlg is derived from CPropertyPage. How to access its member function from a nonmember function in the same CPP file?.

void Non_Member_Get_PorpertyPage()
{
CMyPorpertyPageDlg* pPageDlg = ....
}

View 4 Replies View Related

C++ :: How To Access Member Variables From Main

Nov 10, 2013

my clsLocalStudent inherits from clsStudent. How to i set my accounts information (accountNumber, accountHolderID . . . . .)?

Code:
#include <iostream>
#include "clsInterest.h"
#include "clsDate.h"

[Code]......

View 3 Replies View Related

C++ :: How To Access A Specific Member If Keys Are Same

May 19, 2013

I understand what a map is and all, but what purpose does multimap serve?How can you access a specific member if the keys are the same?

View 8 Replies View Related

C++ :: Access Private Member Variable

Apr 3, 2013

I've created a class called Voter with a private member variable ID, also I have a variable in my main function to be ID as well. I'm trying to compare the two ID's but when I do so:

if (ID == V.ID)

I get the error - 'std::string Voter::ID' is private within this context.

I know that because it's private I can't access it, but how do I?

View 3 Replies View Related

C++ ::  Friend Function Can't Able To Access Private Member

Jan 21, 2015

Am trying to write table object into file. Here's the source code

.hpp file

class Table {
private:
int table_no;
std::string table_type;
bool engaged;
std::time_t start_time;
double total_sec;

[Code] ....

When i compile the above code i get the following error...

table.hpp: In function ‘std::ifstream& operator>>(std::ifstream&, Table&)’:
table.hpp:19:7: error: ‘int Table::table_no’ is private
table.cpp:91:12: error: within this context
table.hpp:20:15: error: ‘std::string Table::table_type’ is private
table.cpp:92:12: error: within this context ...........

View 4 Replies View Related

C++ :: Composition And Member Access Inside Composed Structure

Jan 18, 2013

I have a question regarding composition and accessing members "deep" inside the composed structure. For example;

class A {
private:
int m_myInt;
public:
int myInt() const {return this->m_myInt;};
void myInt(int newInt) {this->m_myInt = newInt;};

[Code] ....

Now, from somwhere I have access to an object of type B where I want to update the A::m_myInt. How would you do this without "breaking" the whole purpose of private/public members?

B myB;
myB.m_a.myInt(3); // Not allowed, and not desireable

I thought about implementing access through functons kind of like;

A & B::a() {return this->m_a;};
myB.a().myInt(3);

but I'm worried that this exposes my B::m_a-object too much. This would allow

myB.a() = A();
, right?

The following is a more desireable way of acces, but doesn't work for updating;

A const & B::a() {return this->m_a;};
myB.a().myInt(3); //Disallowed? myInt(int) is non-const.

What about this? Is this a good way of doing it?

class A {
private:
int m_myInt;
public:
int myInt() const {return this->m_myInt;};

[Code] ....

I guess it works? It would lead to a lot of data shuffling in case of larger sub-components.I would really like to do the following without exposing my components so much:

B myB;
myB.a().myInt(3);

Can it be done?

View 11 Replies View Related

C++ :: Setting Up Linked List Class With Templates?

Dec 2, 2013

I am trying to implement a linked list using a class template, however each of my classes that I want in the list all inherit from an Account class. I have attempted to template the linked list class as account however Ive come into errors I can't resolve. How I can go about this?

The error exists within the customer.cpp class where it says

14IntelliSense: a value of type "Account *" cannot be assigned to an entity of type "CurrentAccount *"f:Further C++Assignment with TemplatesAssignmentCustomer.cpp229Assignment

Customer class:

#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <iostream>
#include <string>
#include "Account.h"
#include "AccountLinkedList.h"

[Code] .....

View 2 Replies View Related

Visual C++ :: Constantly Calling Ostrstream - Private Member Access Violation

Sep 22, 2014

Code:
std::ostrstream oss;
oss << "path for " << unit << "
" << path;
puts(oss.str());

[Code] .....

Today, I just received this new fresh error, I was constantly using them, but just come to know it is a private access violation as the last error of my program. Did I use it in the wrong way?

View 3 Replies View Related

C++ :: Const Method Accessing Private Data Member Giving Access Violations

Oct 17, 2014

My code is here [URL]

void Player::Display() const
{
cout << "
Player Name: " << GetName() <<
"
Grade: " << GetGrade() << "
G.P.A. " << GetGPA() << endl;
}

The problem occurs in here, I get access violations, is there a way to this while keeping Display const or is this code valid and my problem is somewhere else and not being caught in the debugger? I tried to make the return types const - but that didn't work .....

//Getters need const twice for this to work?
const char* Player::GetName() const {return m_name;}
const int Player::GetGrade() const {return m_grade;}
const double Player::GetGPA() const {return m_gpa;}

[Code].....

View 2 Replies View Related

Visual C++ :: Access Variable Inside Class From Other Class

Nov 9, 2013

I am trying to access a variable from another class through another class but it is not returning its "instance"?

Example:
Class View

Code:
...
V3D_Viewer viewer;
...
Class MainWindow

Code:
...
viewer* myView;
myView = new viewer();
...
Class Test

Code:
...
MainWindow window;
window.myView->setBackgroundColor(WHITE);
...

I am new to c++ references and pointers,

View 3 Replies View Related

C++ :: How To Initialize Static Member Of Class With Template And Type Of Nested Class

Oct 7, 2014

How to initialize a static member of a class with template, which type is related to a nested class?

This code works (without nested class):

#include<iostream>
using namespace std;
struct B{
B(){cout<<"here"<<endl;}
};
template<typename Z>

[Code] ,....

View 1 Replies View Related

C++ :: Using Member Function Of A Class In Another Class And Relate It To Object In Int Main

Aug 21, 2013

I am writing a program which is using SDL library. I have two different classes which one of them is Timer Class and the other is EventHandling Class.

I need to use some member functions and variables of Timer in some Eventhandling Class member functions, Although I want to define an object of Timer in int main {} and relate it to its member function that has been used in Eventhandling member function in order that it becomes easier to handle it, I mean that I want to have for example two objects of timer and two objects of Eventhandling class for two different users.

I do not know how to relate an object of a class from int main{} to its member function which is being used in another class member function.

Lets have it as a sample code:

class Timer {
private:
int x;

public:
Timer();
get_X();
start_X();

[Code] ....

View 4 Replies View Related

C++ :: Access Enum Class And Its Values Outside Of The Class

Apr 23, 2013

I cannot wrap my head as to how to access my enum class Azimuth.

Code: #ifndef BOUSOLE_H
#define BOUSOLE_H
#include <iostream>
#include <string>
#include "StringHandler.h"
class Bousole{

[code]...

And here is where I am trying to access my enum for testing/understanding purposes

Code: #include "Bousole.h"
using namespace std;
int main (int argc, char *argv[]){
cout <<"Start bousole" << endl;
Bousole b;

[Code] ....

View 6 Replies View Related

Visual C++ :: SEH Handler Cause Compiler Warnings And Errors

Jan 24, 2014

I use a SEH handler in my code, like this:
__try
{
.. Some codes ...
}
__except(
EXCEPTION_EXECUTE_HANDLER
)
{
TRACE(_T("Exception"));
}
but get the following compiler errors:

1>e: est.cpp(3310): warning C4509: nonstandard extension used: 'CMyClass::Test' uses SEH and 'iterator' has destructor
1> e: est.cpp(3290) : see declaration of 'iterator'
e: est.cpp(3450): error C2712: Cannot use __try in functions that require object unwinding

View 2 Replies View Related







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