Questions tagged [member-access]
63 questions
1
vote
1 answer
What is the use of i in `printf("%d\n",(a->ptr)[i]);`?
Hey guys I am currently learning DSA and in ADT I have a problem:
This is a code that creates a custom array and takes the input of the array and stores it and prints it too but I want to ask that what does that [i] do in printf("%d\n",(a->ptr)[i]);…

Shresth Gour
- 97
- 6
1
vote
4 answers
What is cryptic line of code for this statement?
For example:
temp->next = NULL is same as (*temp).next = NULL
list->next->next = temp is same as ??

TastyPoison
- 23
- 5
1
vote
4 answers
Why private virtual member function of a derived class is accessible from a base class
Consider the following snippet of code:
#include
class Base {
public:
Base() {
std::cout << "Base::constr" << std::endl;
print();
}
virtual ~Base() = default;
void print() const { printImpl(); }
private:
…

David Hovsepyan
- 509
- 1
- 3
- 18
1
vote
1 answer
Does multiple struct (Nested structure) exist in C?
I wonder if there is a way to declare multiple structs in C.
For example, I made this:
struct Team{
char TeamName[20];
int Point;
int Goals;
};
typedef struct TeamCup {
char GroupID;
struct Team team;
}Group;
Group g1, g2;
I…

NewbieBoy
- 73
- 4
1
vote
2 answers
error when using pointers, dynamically allocating ,struct
My code don't run ,how can I fix it
i think i don't understand where i am wrong
error when using pointers, dynamically allocating ,struct
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
struct nhanVien{
int code;
char name[50];
…

Ngoc Anh
- 21
- 5
1
vote
3 answers
how to initialize struct array members inside function by reference
im trying to make an array of struct and initialize struct array member, but I don't know how to access struct member, i used (st->ch)[t] = 'c'; and others similar syntax but i did not succeed.
best regards.
struct ST
{
char ch;
};
bool…

Sofia
- 55
- 7
1
vote
3 answers
Class private member wont change in function
using namespace std;
class map
{
private:
float result= 0;
public:
void func_1();
void setres(float counter);
float getres();
};
void map::setres(float counter)
{
result= counter;
}
float…

Clarence
- 13
- 3
1
vote
2 answers
error: request for member data in something not a structure or union despite using arrow operator
I am facing an error: request for member data in something not a structure or union. I am passing the address of a structure receiver_data in a structure global_vals to a function in another file.
The init_func function receives the address as a…

Wb10
- 89
- 4
1
vote
2 answers
Why can I call this static method using the class name but not using a class instance?
class Program
{
static void Main(string[] args)
{
var p = new Program();
p.Main(args);//instance reference error,use type name instead
var p = new Program();
Program.Main(args);//error disappears
}
}
I…

Canman33
- 39
- 5
1
vote
1 answer
C/C++ macro parameter containing dot (member access operator)
How can one use in C/C++ macro parameter containing dot (member access operator)?
Example:
#define M(obj,y) obj.y##x
struct S { struct {int x;} c; int x; };
S s;
s.c.x = 1;
s.x = 2;
M(s,) // works, 2 (resolves to s.x)
M(s,c.) // error: pasting…

S.V
- 2,149
- 2
- 18
- 41
1
vote
2 answers
Unable to compile c code, when using the macro #define for struct member in header file
I have two files(average.h, average.c). In the definition of a structure i have used #ifdef INTERNAL .
#ifndef AVERAGE_H_
#define AVERAGE_H_
typedef struct str_internal {
int i1;
int i2;
} internal;
typedef struct str_speed {
int…

Nandha
- 752
- 1
- 12
- 37
1
vote
1 answer
Best practice to set single/multiple members of a (property-) class
I have a class that contains some members that may be modified from external sources:
class CNode
{
protected:
// these members might be changed by users
std::string m_sName;
CState m_CurrentState;
CColor m_DiffuseColor;
};
The…

Tomas Dittmann
- 424
- 7
- 18
1
vote
4 answers
Optional logic when passing structures in c++
I am new too programming and am trying to pass an array of structures and an "option" to a function. I then want the function to be able to manipulate the data within the the array of the struct.
struct coordinates{
int x;
int y;
int…

silvergasp
- 1,517
- 12
- 23
1
vote
1 answer
typecast operator in private base
I found something I consider strange behaviour in C++: a typecast operator in a private base class is confusing the compiler when trying to resolve an implicit cast:
#include
struct Base
{
#ifdef ENABLE
operator bool () const { return…

Matei David
- 2,322
- 3
- 23
- 36
1
vote
1 answer
How can accept connection from specific page?
I have a web page and I need to accept some of visitors if it is just from a spesific page.
For Example: If visitor goes example.com/member to example.com/specific it will ok.
But if user goes any other place or just from address bar of browser, It…

Ugur Ozer
- 49
- 7