C++ :: How Do API Call Back To Class Members

Jun 24, 2014

I've been creating an API and I'm now stuck on callbacks. There are many APIs that allow callbacks to class members(e.g. Windows API) using a void pointer to the object. I've searched the internet for hours and I can't find one example of how to use the "hidden object parameter" of an class method pointer that doesn't use std::function/bind or boost::function/bind. Any information on how API's like Windows API are able to use class methods as callbacks

View 6 Replies


ADVERTISEMENT

C++ :: Call Back For Calendar - WINAPI

Jul 10, 2014

I have made a calendar using a resource file and using the winapi

CALENDAR_DLG DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Calendar"
FONT 8, "Ms Shell Dlg" {
CONTROL "", CALENDAR, "SysMonthCal32", WS_VISIBLE, 0, 0, 186, 95
}

My call back function is

BOOL CALLBACK DlgCalendar(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_INITDIALOG: {
} return TRUE;

[Code] .....

DTN_DATETIMECHANGE is not being called ? What is UMSG equal to when a date is changed in the calendar?

View 5 Replies View Related

C++ :: Friendship From Derived Class Method To Base Class Members

Jul 15, 2014

I would like to know if there's a way to make a method from a derived class a friend of its base class. Something like:

class Derived;
class Base {
int i, j;
friend void Derived::f();
protected:
Base();

[Code] ......

View 3 Replies View Related

C++ :: Set And Get The Value Of Different Members In A Class

Jun 28, 2013

I am new to c++ programming and i have written a simple class program to display the name and duration of the project

#include<iostream>
class project {
public:
std::string name;
int duration;
};

[Code] ....

Now i am trying to the write the same program with the usage of member functions using set and get member functions. i have tried the following

#include<iostream.h>
class project {
std::string name;
int duration;
// Member functions declaration

[Code] ....

I am not sure whether above code logic is correct, how to proceed with it.

View 3 Replies View Related

C++ :: How To Define A Class Which Have Two Members

Sep 16, 2013

I want to define a class, which will have two members, for example, vaporPressureStatus and vaporPressure

enum vpStatus_t {nonesense, unknown, known, saturated};
class pore_t {
public:
vpStatus_t vpStatus;
double vaporPressure;
};

when vpStatus is nonsense and unknown, the vaporPressure should not have a value; and if I calculate out a value for vaporPressure, the vpStatus can be set as known.

I am wondering if there is any set, pair or other structure can hold this two members together, so that when I change one's value, the other guy will also change accordingly.

View 3 Replies View Related

C++ :: Why Class Members Private By Default

Apr 14, 2013

The reason that class members are private by default is because, in general, an object of a class should be a self-contained entity such that the data that make the object what it is should be encapsulated and only changed under controlled circumstances. Public data members should be very much the exception. As you’ll see a little later in the chapter, though, it’s also possible to place other restrictions on the accessibility of members of a class.

View 17 Replies View Related

C++ :: Access Other Members Within Same Nested Class?

Jul 12, 2013

It's hard to give a precise title but here is the question in detail: I have a class, something like this:

Code:
class classA{
public:
void fnA();
...
};

and another class that contains objects of classA:

Code:
class classB{
public:
classA A1;
classA A2;
classA A3;
vector<classA*> vA;
...
};
classB B1;

Now is it possible to access B1.vA from B1.A1.fnA() through some kind of pointer chain like this->parent->vA ? If so

View 7 Replies View Related

C++ :: Accessing Private Members From Inside Class

Jan 10, 2013

Let's say I have the following class:

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

Which of the following is to prefer;

int MyClass::myFunc() {
return 2*this->m_myInt;
}
or
int MyClass::myFunc() {
return 2*this->myInt();
}

The second one seems better? Are both OK? What's the best practice?

View 13 Replies View Related

C++ :: Const Static Members In A Template Class?

Jan 17, 2013

I have a little problem with template classes and their specialization. Here is a short example:

template <typename T>
struct A{
// some typedefs

[Code]....

The above example is not compiling, because of the assignment of the const static double. Double needs a constructor, but that doesn't work (or seems not to work) with static.

I'm not sure, if it works at all in C++ that way. All I want is a template struct with some typedefs and a constant which is different for different specializations. Don't think it has to be static, but that would be better style, wouldn't it?

View 3 Replies View Related

C++ :: Cannot Access Protected Members Of Parent Class

Oct 22, 2014

I am doing C++ data structures exercises, and I am still learning some of the more basic concepts. I have a parent class:

template<class T>
class linkedListType {
public:
protected:
int count;
nodeType<T> *first;
nodeType<T> *last;
private:
};

Derived class:

#include "linkedListType.h"
template<class T>
class orderedLinkedList: public linkedListType<T> {
public:
void mergeList(orderedLinkedList<T> &list1, orderedLinkedList<t> &list2) {
first = list1.first;
...
} private:
};

There is more code in my mergeList() function, but I included the line that is giving me problems. The error that my CodeBlocks compiler is giving me is that 'first' was not declared in this scope.

Strangely enough, if I change it to this->first, the error disappears.

1. Why does it not recognise 'first'?
2. Why would this->first work at all? Is the 'this' object a smart pointer?

View 1 Replies View Related

C++ :: How To Put File Data Into Members Of A Class - Array Transferring

Mar 10, 2013

I'm trying to put file data into members of a class. Remember to type in the file name you want to open. Cool feature right? I just had Dbase.txt so I chose that.

Fixed stuff in the .txt. Now I need to figure out why it only does 1 set and then ends.

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class INFO {

[Code] .....

Dbase.txt:
Bob
Guy
Programmer
M
9999.99
40
------------------
Little
Guy
Little Brother
M
0.0
3
------------------

View 14 Replies View Related

C++ :: Storing A Class With String Members Into Binary Files

Nov 17, 2014

Im trying to make a c++ program for a school project, and i need to store the information into binary files, but I'm having some problems trying to store a class with string members, for example:

class whatever{
protected:
string name;
public:
(List of functions)
}

But if I do that, my code just dont work when I write and read a binary file, but if I change the string to char array, for example:

class whatever{
protected:
char name[20];
public:
(List of functions)
}

It works good, so I wanted to know if there's some way to store a class wiht strings in binary files, or what am I doing wrong?

View 4 Replies View Related

C++ ::  Storing Static Class Members Of Dynamic Variable Type In DLL

Oct 15, 2013

How I can implement it.

Tickable.h

#include <list>
#ifdef TICKABLE_EXPORTS //Automatically defined by MSVS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#pragma comment(lib, "Tickable.lib")
#endif

class DLL Tickable{

[Code] ....

error LNK2001:
unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST
PATHTickable.obj

I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.

Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?

I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.

View 5 Replies View Related

C++ :: Can Base Class Call Overridden Function From Derived Class?

Aug 28, 2013

I just wondering if a base class can call the overridden function from a Derived class?

Here's an example:

//Base Class H
class BaseClass {
public:
BaseClass();
virtual ~BaseClass();
virtual void functionA();

[Code] ....

So basically, when I am creating a new object of Derived class, it will initialize BaseClass and the BaseClass will call functionA but I want it to call the function overridden by Derived class.

I know that if I call newObj->functionA it will call the overridden function. Right now I want the base class to call the overridden function "this->functionA(); in BaseClass" during its initialization. Is it possible to do that?

View 9 Replies View Related

C++ :: Calling Custom Constructor Of Element In Array Whose Class Has Const Members?

Apr 15, 2013

If I have an array of some class, and that class has const members, is there some way I can call a custom constructor on elements of the array?

I can't seem to reinitialize an element in foos in the example below. A thread on stack overflow mentioned the copy constructor show allow it, but I get "no match for call to '(Foo) (Foo&)'" when I try it.

Code:
class Foo {
public:
Foo();

Foo(int x, int y);

[Code] .....

View 4 Replies View Related

C++ :: Nested Classes - How Members Be Accessed Through Object Of Enclosing Class Type

May 18, 2013

"A nested class has free access to all the static members of the enclosing class. All the instance members can be accessed through an object of the enclosing class type, or a pointer or reference to an object."

How can the members be accessed through an object of the enclosing class type? I understand the pointer and reference part because for them you dont need the full definition, but for creating a object you do?

Also it has free access to all static members because the nested class is part of the enclosed class and with static it exists in everything inside the enclosing class? Right or am I missing something?

View 4 Replies View Related

C++ :: How To Call Function From Derived Class In Base Class

Dec 24, 2013

Basically, I have a base class called MainShop and it has 3 derived classes which are SwordShop, SpellBookShop and BowShop. I want the base class to be able to call a function from one of the derived classes but no matter what i do, it doesn't seem to work!

Here is my code:

#include "MainShop.h"
//BaseClass cpp
void MainShop::EnterShop(Hero& hero)

[Code]....

I have two other derived classes, but its basically the same concept. I have a function in one of the derived classes and i would like to call it from the base class. This is one my derived classes:

//SwordShop derived cpp
#include "SwordShop.h"
void SwordShop::soldierShop(Hero& hero)
{
/* some code here*/
}

View 4 Replies View Related

C++ :: Call From Class Created Inside A Class

May 21, 2014

I have 2 Classes.
-> StateManager
-> Intro

The StateManager creates the Intro. I want that the Intro calls a function of the StateManager if finished. How can I achieve that?

At line 24 at the Intro class you can see what I tried.

StateManager:

#pragma once

#include "State.h"
#include "Intro.h"
class StateManager{
private:
std::vector <State*> States;

[Code] .....

View 5 Replies View Related

C++ :: Do Static Functions Have Access To Non Static Data Members Of A Class

Apr 17, 2013

From my book:

"A static function might have this prototype:

static void Afunction(int n);

A static function can be called in relation to a particular object by a statement such as the following:

aBox.Afunction(10);

The function has no access to the non-static members of aBox. The same function could also be called without reference to an object. In this case, the statement would be:

CBox::Afunction(10);

where CBox is the class name. Using the class name and the scope resolution operator tells the compiler to which class Afunction() belongs."

Why exactly cant Afunction access non-static members?

View 7 Replies View Related

C++ :: How To Call Methods Of Class

Feb 27, 2014

how to call the methods of the class.I have an object call v which is an array and I don't how to call the methods of the class. The error is here:

v.readDates(v[a]);

#include "Date.h"
#include <iostream>
using namespace std;
int main(){
int a;
cout << " HOW MANY DATES DO YOU HAVE? " << endl;

[code]....

View 3 Replies View Related

C/C++ :: Input Call By Value In Second Class

Feb 1, 2015

I am trying to input a call by value in the second class. It will not compile with how it is currently and says that the pounds needs to be a different variable. Why is this? Is this close to a call-by-value or am I way off?

#include <iostream>;
using namespace std;
int main() {
int a, b, c, d;
cout << "Please enter your weight in Pounds and Ounces ";

[Code] .....

View 2 Replies View Related

C++ :: Member Function In Derived Class Call Same Function From Its Base Class?

Sep 18, 2013

How can a member function in my derived class call the same function from its base class?

View 1 Replies View Related

C++ :: No Matching Function For Call To Class

Nov 4, 2014

I'm having this pain in the ass error (No matching function for call to Data::Data() ) on this block of code:

Etapa::Etapa(string nm, float dist, string loc, Data dt) {
nome = nm;
distancia = dist;
local = loc;
data = dt;
}

[Code].....

I guess this is happening because I'm trying to give Etapa an argument of Data type and I can't do it or put it in a variable since it has 3 parameteres (mes, dia, ano).

View 2 Replies View Related

C++ :: A Call To A String Names In A Class Not Display

Apr 19, 2014

I created class called students which suppose to store students names of any sizes in an arrey but when I call the display function it does not show the names.

#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
class students{
public:
string names[SIZE];

[Code] ......

View 1 Replies View Related

C++ :: Compiler Will Not Allow To Call A Public Method In Another Class

Feb 23, 2013

I have read the book over and over and I thought I understand "CLASS". But when I applied it and write the code the compiler tells me that there is a compiling error.

1. I have this method addProduct(Product* pProduct) in a Class called ProductRack, the code is in ProductRack.cpp file. The declaration of the Class methods and private variables are in ProductRack.h header file.

2. But when I call a method in the DeliveryCHute Class from the ProductRack Class I get a compiler errors which are these:

A.IntelliSense: a nonstatic member reference must be relative to a specific object
B.error C2352: 'Project1::DeliveryChute::insertProduct' : illegal call of non-static member function

And this is causing the error:

if (Project1::DeliveryChute::insertProduct(pProduct) == false)

//THIS IS JUST ONE METHOD INSIDE ProductRack.cpp
bool
Project1::ProductRack::addProduct(Product* pProduct) {
// Todo : Implementing
if (Project1::DeliveryChute::insertProduct(pProduct) == false)
return true;

[Code] .....

View 5 Replies View Related

C++ :: Function Does Not Update Class Variables In Recursive Call

Dec 14, 2014

I'm trying to implement Tarjan's Strongly Connected Components Algorithm in C++. Here's how I gotten so far:

void tarjan(vector<Vertex>& G){
index = 0;
while (!S.empty()) S.pop();

[Code]....

Here's an example graph for the algorithm to run: [URL]

Here's the first part of the output of the program: [URL]

all the index & lowlink values of the nodes are set to -1 in the beginning. global index value is set to 0. My problem is, the algorithm starts running on Vertex X-4. It runs the instruction X-4.index=0 & X-4.lowlink=0 then it calls itself with the paramater of node X-1. it sets X-1's index & lowlink values to 1. then it calls itself for X2. then it checks whether node X-4 has the index value <0 or not. Even though we set the value of X-4 to 0 in the first run, it still sees X-4.index as -1.

View 1 Replies View Related







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