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


ADVERTISEMENT

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++ :: 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++ :: Nested Class Vector Index Access?

Mar 22, 2014

Is it possible to pass the vector index '4' to the Height() function without passing it as a parameter of the function.

Basically, I'm trying to eliminate using 4 twice... what I'd LIKE the statement below to look like is this:

gx.Cell[4].Height();

The only way I can figure out how to get it to work is like this...

class grid{
public:
class CELL{
public:
int Height(int index); //returns the height of this cell

[Code] .....

View 8 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 Access Name And File Name Members

Sep 8, 2014

How to access the name and file name members on line 42 and 43?

Code:

typedef struct {
char * name;
char * filename;
} FILES;
FILES * files[256];
}

[code]...

How to access the name and filename from within function?

*files[count].name = chTmp;

View 9 Replies View Related

C :: How To Access Members Of Referred Array

Sep 11, 2014

files.c
Code:
#include "include/types.h"
#include "include/gaussian.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

[Code]....

I need to access the members .name and .filename to allocate memory and copy strings in there.

Code:
files[count]->name=malloc(64);
files[count]->filename=malloc(64); SIGSEGV error

How to make the reference working?

View 12 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++ :: Template Operation - Cannot Access Non-Public Members

Feb 5, 2015

Code:

template <size_t s>
class foo {
public:
foo()
{
}
template <size_t l, size_t r>

[Code] .....

The above doesn't want to compile.

error C2995: 'foo<l+r> operator *(const foo<s> &,const foo<r> &)' : function template has already been defined
see declaration of 'operator *'
see reference to class template instantiation 'foo<s>' being compiled
with
[
s=4
]

If I change the operator to return a foo<s> it does compile (but that's not the behaviour I need).

if I move the operator to outside the class (removing the 'friend') it does compile and behaves how I need, but I can't access non-public members so I can't write the implementation correctly.

View 6 Replies View Related

C :: How To Access Nested Structure Using Pointer

Jan 22, 2015

I need to know how to access the nested structure using pointer, i mean i know how to do that when i have simple structure, for example:

Code:
struct person{
char fname[16], lname[16];
int age;
}

for this example i can use

Code: (*pointer).age
or
Code: pointer->age

But if i have structure like this:

Code:
struct date{
int day, month, year;
}
struct person{
char fname[16], lname[16];
struct date birthDate;
}

Then how can i access the birthDate using pointer?

View 2 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++ :: 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

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++ :: 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++ :: 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

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++ :: 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++ :: 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++ :: 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++ :: Friend Of Nested Template Class

Nov 9, 2013

Consider the following program below, which compiles without a hitch on MinGW GCC 4.8.1:

template <typename T>
class Outer {
class Nested1 {};
template <typename U>
class Nested2

[Code] .....

Is there any way I can move the definition of func outside of the class?

View 1 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++ :: Cannot Define Method Of Inner Nested Class If It Is Private

Jan 16, 2013

it seems that I cannot define a method of an inner nested class if it is a private class. for example:

class outter {
class nested {
void foo ( void ) {} // okay - but is this inline?
} void inner::foo( void ) {} // not okay - cannot define inside another class
} void outter::inner::foo( void ) {} // not okay - 'nested' class is private!

what I want to know is, is there another way to define an inner class's method? and if not, is it eternally doomed to be inline because it has to be declared inside it's own class declaration?

View 5 Replies View Related

C# :: Invoke Method In Nested Class Using Reflection

Jun 25, 2014

I am having problems invoking methods in a nested class using reflection. I have the following:

A parent class, Group, that holds instances of a simple class called Signal. I want to modify the number of instances inside the group class often. So, all my code has to be dynamic and use reflection to know how many instances of signal there are inside the Group class.

class Group{
public static Signal name1 { get; set; }
public static Signal name2 { get; set; }
public static Signal name3 { get; set; }

[Code]....

I had no luck invoking the method of the instances of signal class that are inside the Group class. I tried getting the methods name using getMethods() but could not navigate through the syntax.

How could I invoke and pass parameters to the method of the instances of signal using reflection? Is there a better way of accessing the properties and methods of nested classes?

View 4 Replies View Related







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