Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
268 views

C++ Member Initializer Lists Problem: Declaration Order on Private Member Variables

This is my first ever question posted on Stack Overflow, hope someone could explain it. So basically the two classes are the same except the order of the private member variables. The output is 10 20 ...
lionelmayhem's user avatar
-2 votes
1 answer
86 views

cpp inheritance some misconception

here i have some code class A{ private: int a; public: void abc() { cout << a << endl; } }; class B : public A { }; main() { B obj; obj.abc(); // it works but why? obj.abc ...
Ehtisham's user avatar
5 votes
4 answers
5k views

What does it mean to be a private member (c++ classes)?

I am a little confused about private data members in C++ classes. I am new to coding and still in the middle of my 'Classes' chapter so I might be ahead of myself, but I feel like I am missing a piece ...
Luc Aux's user avatar
  • 189
1 vote
2 answers
69 views

C++ Private variable not readable from secondary class

I have two classes, and in one of them i have a private variable. There is also a member function to change this variable and a get function to read it. Such class could look like this. class Toggler ...
Chris's user avatar
  • 43
3 votes
5 answers
2k views

C++ is it possible to NOT inherit a member?

I am pretty sure it isn't but I am going to ask anyway... Here's an example: let's say I have a class called Elipse: class Elipse { private: double d_m_lAxis; // the length of the large Axis of the ...
AlanKalane's user avatar
  • 1,031
-1 votes
1 answer
756 views

C++ initialize member array

I am trying to create a class (foo) with a private member array. This class will be used as a private member of another class (foo2) in the constructor of which the array will be initialized. example....
loogikos's user avatar
-2 votes
2 answers
58 views

Trouble accessing an object's private function

I have an assignment in which I cannot edit two header files, car.h and compass.h. In the file, car.h, there is a private function called: void load_car();. This is later defined in car.cpp as: void ...
PhilThePenguin's user avatar
0 votes
2 answers
356 views

How to restrict objects private data member modification in C++?

please check the below code, i need a solution to restrict the modification of private data members of class A. please suggest. class A{ private: int a; int b; public: A(int i=0, int j=0)...
d3v-sci's user avatar
  • 173
0 votes
1 answer
126 views

Error with Node of Tree Class, perhaps because of private Node members

So I've been testing a tree node class and have encountered some errors. I think it's because I'm using private Node members and using accessor functions to access them. Using the del function, I ...
dfries's user avatar
  • 1
4 votes
5 answers
4k views

C++ : generic getter/setter for each single member of private struct

Probably a common one, but can't find any existing topic here. So I have a class with a private struct with many members. I want to write getters and setters for single members, but it would be long ...
C. THIN's user avatar
  • 147
0 votes
0 answers
165 views

Friend ostream cannot access private member

I know this has been asked several times, but I really couldn't get a solution out of the other questions. So, I am losing my mind on why the ostream operator<< can't access the private section ...
user5753059's user avatar
0 votes
2 answers
67 views

Class private member - array accessing failed

So I have this code in C++ which is just exercise in learning C++: #include <stdio.h> #include <stdlib.h> #include <time.h> int random(int max){ srand(time(NULL)); return ...
knowledge's user avatar
  • 401
1 vote
1 answer
43 views

Compile-time error building a simple partial array class in C++

I'm having trouble getting my Partial Arrays class to compile. In one of my member functions I call for a previous member function and get the error "member reference base type 'ITEM_TYPE [255]' is ...
Jac7k's user avatar
  • 37
-3 votes
2 answers
95 views

access private member variable through private member, same class

// M9P369.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> const int MaxSize = 100; using namespace std; class Set { int len; // ...
B-Tank88's user avatar
-1 votes
2 answers
228 views

C++ Isn't this a useless inline declaration?

This is another question about inlining a function. But I will take possible comments and answers right away: Defining a function inside a class makes it inline automatically. The same behaviour can ...
Noël Widmer's user avatar
  • 4,582

15 30 50 per page