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


ADVERTISEMENT

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++ :: Assign A Class Value To Another Nested Classes?

Jul 17, 2013

this is the first time to ask my question on Cplusplus. my qustion is i got this message when i trying to run this code:

object.h
#ifndef __NCTUNS_nslobject_h__
#define __NCTUNS_nslobject_h__
#include <stdio.h>

[Code].....

so, my problem is when the compiler starts compiling it stops on this code :

NslObject::newKeyPair (RSA::GenerateKeyPair(keyLength));

and the appeared message is :

Error:
object.cc: In function ‘void Set_KeyPair()’:
object.cc:53: error: no match for call to ‘(KeyPair) (KeyPair&)’

so, how could i assign a generated keypair class value to NslObject::newKeyPair.

View 2 Replies View Related

C++ :: How Are Members Accessed In AMP Restricted Methods

May 17, 2013

Suppose I have a class "A", which has a method "void AMP_call()" that calls paralel_for_each in which another method, "float amp_function(float) restrict(amp)". When I call that method, can it then use members of "A"?

class A {
void AMP_call();
float amp_function(float) restrict(amp); // do something on a device
float allowed_variable;
std::vector<bool> not_allowed;

[Code] ....

Another way to frame my question, perhaps to make it easier to understand what I am after, would be that I want to know what happens if an amp-restricted method is called where the body of the class itself (which is not amp-compatible and afaik doesn't have to be since it's not passed to the device) may contain members that are not amp-compatible.

All of the msdn blogs I could find deal with which functions and methods can be called from within a parallel_for_each loop, but not with which variables are available to the lambda function itself.

View 9 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++ :: 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++ :: Object And Classes - Declaration Of Variable Using User Defined Type

Mar 17, 2013

I am getting a compilation error from the code below. It is when i am naming a variable with my user defined type.

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class person {

[Code] .....

C:Dev-CppTRIAL.PASS.!!!.cpp In function `int main()':
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected primary-expression before "p"
66 C:Dev-CppTRIAL.PASS.!!!.cpp expected `;' before "p"
74 C:Dev-CppTRIAL.PASS.!!!.cpp `p' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
83 C:Dev-CppTRIAL.PASS.!!!.cpp `X' undeclared (first use this function)

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++ :: Create A Class Type Structure Using Struct Instead Of Classes

Apr 16, 2013

I am trying to create a class type structure using struct instead of classes.

Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
struct myclass {
int * array;
int nelements;

[Code] ....

Guess what I am asking is using the pointer in the first code section better or is there another way'. I don't know about making the second code work.

View 3 Replies View Related

C++ :: Declare Template Type Object Inside Template Type Class Definition

Oct 12, 2013

Let me put it into the code snippet:

/**
This class build the singleton design pattern.
Here you have full control over construction and deconstruction of the object.
*/
template<class T>
class Singleton

[Code]....

I am getting error at the assertion points when i call to the class as follows:

osgOpenCL::Context *cxt = osgOpenCL::Singleton<osgOpenCL::Context>::getPtr();

I tried commenting assertion statements and then the debugger just exits at the point where getPtr() is called.

View 7 Replies View Related

Visual C++ :: Operator Overload Not Defined Error When Type Accessed Through Const Struct

Oct 17, 2012

I have a basic vector/point class where I've overloaded a bunch of arithmetical operators:

Code:
#pragma once
class point {
public:
point() {
}
point(float p_x, float p_y, float p_z) : x(p_x), y(p_y), z(p_z)

[Code] ...

I can use it fine like

Code:
point p(50,50,50);
point q(50,50,50);
point t = p * q + q;

However when I put this point type into a struct and try to access the members after passing it through by const reference:

Code:
struct sextic {
point a,b,c,d,e,f,g;
};
inline static sextic sexticDifference(const sextic &p_sextic1, c

[Code] ....

This gives me an "operator not defined" error for compilation.

View 2 Replies View Related

C++ :: Nested Classes And Structs

Mar 12, 2014

I'm working on a project involving nested classes and structs like this:

Code: class A {
public:class B {
public:f()
{A::C* iCanDoThis; //no errors.
iCanAlsoDoThis->root->.... //this also works fine.}private:A::C* iCannotDoThis //this is what I would like to do.
Has errors
A* iCanAlsoDoThis;};private:struct C
{..data..};

C* root;};

Is it possible make a pointer to struct C a private member of class B?

View 1 Replies View Related

C++ :: Linked List With Nested Classes

Apr 30, 2013

how I would execute a nested class in a linked list... As example;

[Character][Weapon][Spell] classes are children of a [Base] class that stores normalized information such as 'Name'...

I am aiming to have a unique Character with a unique Weapon and Spell. I am trying to link-list these to have multiple characters. I just can't apply the design logic into programming logic.

cNode.h
#pragma once
#include "Includes.h"
class cNode

[Code]....

View 1 Replies View Related

C/C++ :: Nested Classes Aren't Reading Others As Types

Apr 4, 2015

I have a program to make a contact book. Included below i will post both header files and cpp files of my contact book, my contact class, and my address class. and my main.cpp. The reason address and contact are separate was because my teacher had us do an exercise where we used a header file of someone else's code, and didn't know what the functions actually implemented. But as the project has progressed he gave us the cpp for address.

Main.cpp
#include "Address.h"
#include "ContactBook.h"
#include "Contact.h"

[Code].....

View 9 Replies View Related

C++ :: Threads Giving Error - Call Of Object Of A Class Type Without Appropriate Operator Or Conversion

Jan 27, 2015

I made a simple binary tree then decide to try out threads too. I got the following error:

call of an object of a class type without appropriate operator or conversion

Code:
#include "Tree.h"
#include <iostream>
#include <thread>
void main(void){

[Code] ....

I am having a hard time figuring out why the error exists. I tried adding the new operator but that did not work.

View 11 Replies View Related

C++ :: How Could Object Access Its Private Data Members From Outside

Nov 12, 2013

How does an object access its private data members in copy constructor.

The relevant part of the code: Code: C::C(const C &obj)
{
x = obj.x;
y = obj.y;
}

Normally the object1 called "obj" cannot access its private data members outside. But in this situation it can access. How can it be explained?

Here are the complete code:

Code:
#include <iostream>
using namespace std;
class C{
public:
C(int,int);
C(const C &);

[Code] .....

View 7 Replies View Related

C++ :: Accessing Private Members Of Same Struct Type

Mar 26, 2013

I've been reading the tutorials on Friendship and Inheritance [URL] ..... but I still don't understand why I can't access members of the same struct type.

bool wordBeginsAt (int pos) {
if (pos == 0)
return true;

///use the 'message' string
Message go;
return isAlphanumeric(go.messageText[pos]) && (!isAlphanumeric(go.messageText[pos-1]));
}

The code above is located in a source file, where the function isAlphanumeric passes a char value, and Message is the struct containing the string I want to access. Below is the declaration of the struct and string located in the corresponding header file.

struct Message{
.
.
.
private:
std::string messageText;
};

My frustration comes when I try to call and assign messageText like the tutorial does to its private members, but I keep getting an error saying I can't access the string because it is a private member. Is there a way to access the string without having to pass it through the function wordBeginsAt?

View 6 Replies View Related

C/C++ :: How To Increment Data Members Of Dynamically Created Object

Jun 26, 2012

I am to first increment data members of object that has not created dynamically (i have done with this part),now i have created object dynamically and how to increment its data which i have passed as argument as:

obj3 = new manage(35 , 36)

View 4 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++ :: Cast Directly Between Base Classes Of Object?

Jul 1, 2013

I've got two classes, which are both derived from the same two base classes. Here's a representation of the actual code:

Code: #include <vector>
class BaseClassA {
};
class BaseClassB {
};
class TestClassX
: public BaseClassA,
public BaseClassB

[code].....

Basically, I'd like to know if it is possible to cast directly from a BaseClassA pointer to a BaseClassB pointer, without casting to the child class first.

View 10 Replies View Related

C/C++ :: Unexpected Behavior For Classes That Contain Member Object

Apr 1, 2014

I have a WordRecord that contains a LinkedList (both my doing). I have rigorously tested my LinkedList class, and know that it works (heck, I used it in the last project I had!). The problem is that undefined behaviour seems to happen when using the WordRecord, which has a std::string and a LinkedList<unsigned>. (The problem happens with the LinkedList.)

Here is the code:

main.cpp
#include <iostream>
#include "BinaryTreeNode.h" // here for test purposes
#include "LexicographicTree.h"
#include "LinkedList.h"//also for test purposes
#include "OutputStream.h"
#include "WordRecord.h"
using namespace std;
int main()
{
// setup the OutputStream to print to "test.txt"
OutputStream stream("test.txt");
// create a sampleWordRecord (make it have the word "I" on line 1)

[code]....

One of the requirements for the project is that it must compile on Unix server (I am using Windows, and have tested it in both environments.) I get a core-dump in the Unix environment. On the other hand, the output on-screen in the Windows environment looks right. However, when I open up the text file, I get the following

Sample word record:

WordLines
I{14}
/* I have no what is happening to sampleWordRecord's LinkedList; I am not trying to modify it, except for where I created the sampleWordRecord! */

View 14 Replies View Related

Visual C++ :: Include Object From Another ATL COM DLL - Employee Classes?

Nov 7, 2014

This refers to an ATL COM DLL project. I can successfully create a class hierarchy of objects, ie. say, one class is the TEAM, which then holds other objects, say, a leader and a secretary, both of which are Employee Classes . Here goes my question:

a) In the Team.h header file I declare m_pLeader as a CComPtr<IEmployee>

Code:
classATL_NO_VTABLE CTeam :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CTeam, &CLSID_Team>,
public IDispatchImpl<ITeam, &IID_ITeam, &LIBID_BUOBJ05Lib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
private:
CComPtr<IEmployee> m_pLeader;
CComPtr<IEmployee> m_pSecretary;

b) The Employee Class is defined within this ATL COM project.
c) In the Team.cpp file, I create an instance in the FinalConstruct code, the focus is on the CEmployee

Code:
HRESULT CTeam::FinalConstruct(){
CComObject<CEmployee>* pLeader;
HRESULT hr=CComObject<CEmployee>::CreateInstance(&pLeader);
if (FAILED(hr))
return hr;
m_pLeader=pLeader;
// ..same for secretary...
return S_OK
}

d) Here comes my QUESTION: How must I proceed if the Employee object was part of another ATL COM DLL, that is it would be described in another DLL that I would now like to reuse? I guess I need to

1. Have the other DLL's idl-, tlb, and h file in my project folder. Let me name it "other.h, other.idl, other.tlb"

2. Both h- and cpp-file must have an #include "other.h" statement -- please correct if I am wrong..

3. ...but how must in the Team's h- and cpp-files the statements be (assuming the class in the "other" Dll is Member (instead of Employee? I know the following code will NOT work, so I am asking how it should be correctly?

Code:
private:
CComPtr<IMember> m_pLeader;

4. and in cpp file for:

Code:
CComObject<CMember>* pLeader;
HRESULT hr=CComObject<CMember>::CreateInstance(&pLeader);
[/code]

View 10 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++ :: How To Get Object Of Original Class From Function Of Other Class Where Other Class Object Is Member Of Original Class

Jan 21, 2013

The case is like

class B{
public:
somedata;
somefunction();
}
class A{
public:
data;
function();
}

in somefunction i want a pointer to current object of class A m new to c++

View 2 Replies View Related

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 View Related







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