FAQ Database Discussion Community


Incomplete pointer used in child class - Error: use of undefined type

c++,pointers,inheritance,protected,circular-dependency
Okay... I have understood this question about circular dependency and forward declaration, but I am having trouble understanding a particular error that involve inheritance and pointer-based variables. I will show snippets of the relevant code: Player is the derived class from Entity Entity.hpp class Entity : public sf::Sprite{ private: int...

Java - Protected field not accessible from the subclass? [duplicate]

java,protected
This question already has an answer here: Understanding java's protected modifier 4 answers I am in process of learning the Java access modifiers. For that, I have created a class Machine: package udemy.beginner.interfaces; public class Machine { public String name; private int id; protected String description; String serialNumber; public...

What's the implication of protected keywords in class definition in Scala?

scala,class,generics,covariance,protected
I'm learning Scala by working the exercises from the book "Scala for the Impatient". One exercise asks that: The file Stack.scala contains the definition class Stack[+A] protected (protected val elems: List[A]) Explain the meaning of the protected keywords. Can someone help me understand this? protected obviously makes sense for member...

How do i change a variable of another class?

java,android,static,protected,non-static
I have a variable in the class "MainActivity" with the name modeNr, it is protected so it should be accessible from within the package, however whenever I try to alter it from a class in the same package it gives the error: "Non-static field 'modeNr' cannot be referenced from a...

why public methods are there in object class?they can be protected and will keep thing more private

java,private,public,protected,access-specifier
As for java architecture is concern "to keep things as much private as possible".Thats why finalize method is protected in object class. protected void finalize() throws Throwable { } Why is the finalize() method in java.lang.Object “protected”?please have a look on Mehrdad Afshari answer. then why many other method like...

Is this way to extend a library with virtual protected methods safe?

c++,protected
An external library that I'm using has the following structure: #include <stdio.h> struct A { protected: virtual void f() {} }; struct B : A { void f() {printf("B\n");} }; I have now extended this library by struct C : A { void f() {printf("C\n");} }; Now I would like...

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

c++,inline,private,member,protected
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 be achieved by marking a function with inline outside of the class. An inline function doesn't have to...

How to make a protected file list on my server?

protected,.htpasswd
I've a silly question. I did not create a protected list of folder and file on my server with htaccess. I've a folder protect with htpasswd. There is this in my htaccess : AuthType Basic AuthName "My Protected Area" AuthUserFile .htpasswd Require valid-user But when i add this line for...

Template class hierarchy friend inheritance

c++,templates,protected
I'm tinkering with C++ and are facing the following problem: Given: class A { int aVar; public: A(){} virtual ~A(){}; }; template<class BASE> class B: public BASE { int bVar; public: B() : BASE() {} virtual ~B() {} }; template<class BASE> class C: public BASE{ int cVar; public: C() :...

trying to call protected function of parent class in child class in c++ [duplicate]

c++,inheritance,protected
This question already has an answer here: accessing a protected member of a base class in another subclass 6 answers I always thought that I understand inheritance, but obviously, I don't. I would like to call a protected member function of another instance of the same parent class from...

C++ create base class instance in derived class member functino when the base class constructor is protected

c++,constructor,protected,base,derived
Given the following code: class A { protected: A(){}; // compilation error public: void foo(){cout << "A\n";}; }; class B : public A { public: B() { }; void foo(){ cout << "B\n"; A A(); // OK A a1; // compilation error } }; If I changed the base class...

Access Protected Members of a enclosing class [Nested Classes]

c++,class,nested,protected
I got the following code: class enclosing{ protected: int var1 = 2; int var2 = 4; public: class problem{ friend enclosing; public: void DoStuff(enclosing&e1){ int Sum = e1.var1 + e1.var2; } }i1; }e1; My question is, how do i access the protected member variables of the enclosing class? Is this...

Google spreadsheet - Error when Remove range protection

javascript,google-apps-script,google-spreadsheet,protected,named-ranges
Here's my script, but I can't get it to work for some weird reason??!!! Driving me nuts. function removeThenSetProtection() { // Remove all range protections in the spreadsheet that the user has //permission to edit. var ss = SpreadsheetApp.getActive(); var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); for (var i = 0; i <...

Why protected scope is not working?

java,protected
I am trying an exercise with Java's protected scope. I have a Base class in package1: package package1; public class Base { protected String messageFromBase = "Hello World"; protected void display(){ System.out.println("Base Display"); } } and I have a Neighbour class in same package: package package1; public class Neighbour {...

Protected member function address in derived class is not accessible

c++,inheritance,protected,member-function-pointers
#include <iostream> class A { protected: void foo() {} }; class B : public A { public: void bar() { std::cout << (&A::foo) << std::endl; } }; int main() { B b; b.bar(); } Here I am trying to get address of protected member function of base class. I am...

Accessing protected member's public method

c++,protected
Say I have a class Permissions which has a public method change(). class Permissions { public: change() } I have another class File which has a protected Permissions data member and a public method getPermissions(). class File { protected: Permissions perm; public: Permissions getPermissions() { return perm; } const; }...

Protected member conflict with overloading operator

c++,class,inheritance,protected
I have the following classes: class Base { protected: int myint; }; class Derived : public Base { public: bool operator==(Base &obj) { if(myint == obj.myint) return true; else return false; } }; But when I compile it, it gives the following errors: int Base::myint is protected within this context...