Questions tagged [class-constants]

In object-oriented programming, a class constant is a constant defined within a class.

In object-oriented programming, a class constant is a defined within a .

97 questions
1
vote
1 answer

Java using HashMap with switch statement

I have a constants class where I saved HashMaps of constants like: import java.util.HashMap; import java.util.Map; /** * Constantes de uso general en el programa. */ public final class Consts { // Opciones del menu de juego. public…
iusting
  • 7,850
  • 2
  • 22
  • 30
1
vote
3 answers

Php constant() not working with namespace?

The following does not work: use application\components\auditor\AuditLevel; public function actionAudit() { $data=unserialize($_POST['data']); $message=$data['message']; $context=$data['context']; $level=$context['level']; …
JorgeeFG
  • 5,651
  • 12
  • 59
  • 92
0
votes
2 answers

Can I use constant variables and simple or constant function in the same program?

constant variables and functions in the same program cpp #include using namespace std; class student { public: const int roll; const string name; student (int r,string n) :roll(r),name(n) { …
0
votes
1 answer

More complex diamond problem instance. How to make it work with constant fields?

Let us consider ordinary diamond problem but slightly improved. Now class A have constant fields. struct A { const int a; A (int _a): a(_a) {} }; struct B: virtual A { const int b; B(int _b, int _a): A(_a), b(_b) {} }; struct C:…
0
votes
1 answer

Problem matching apparently similar types in Haskell

This small program works well with concrete types of Int but I wanted to try to make the function the most general with type constraints. The problem is that I don't understand the error message as the two "rigid types" seem to have the same…
niic
  • 83
  • 1
  • 1
  • 6
0
votes
1 answer

Rails constant assignment

I'm reading rails autoloading_and_reloading_constants. In the section 2.2 Class and Module Definitions are Constant Assignments I understood the part where it says class Project < ApplicationRecord end evaluates to Project =…
Ankit Wadhwana
  • 325
  • 3
  • 9
0
votes
4 answers

How to use a global constant instead of a class constant in PHP version 5.6

I'm using Monolog to create my app's logging system. In the core app file, after I create a new Monolog object, I need to select the log level that I want to print in the log file. I want to use a global constant LOG_LEVEL which could be 'DEBUG',…
Godryc
  • 3
  • 1
0
votes
2 answers

Eiffel: once function has generic or anchored result. Trying to create constants

I'm trying to create some terminal logging colors to be able to see clearer my errors. Doing that it seems to me obvious that I'd have to create constants like followings. As I don't want to create an instance each time I call my constant, it makes…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

PHP 5.3 to PHP7 - Undefined class constant 'self::MYCONST'

I have a project running on PHP 5.3.21 that I am trying to migrate to PHP 7.0. The project uses a lot the structure as in the example below:
Sherman
  • 36
  • 5
0
votes
1 answer

Redefining Codeigniter slug-based constants in the model per user

I have a Content Management System, where slug-based constants for each logged-in user's appropriate directories are defined for one or all controllers within the model. I happen to stumble upon this find by experimenting with redefining constants…
imparante
  • 503
  • 9
  • 21
0
votes
2 answers

Member integer changes when directly instantiated from another class

Say I have two classes, A and B. A has an integer, which it displays in the console from its constructor. It also has a member object of B. B displays an integer just like A, but it gets its integer from A when A creates it. The integer must go…
user3152847
0
votes
0 answers

Using a Model Variable in another Model that is related

I'm currently trying to run variables that are declared in a model in a function for checking and creating an email user. The issue I'm having is that the variables being declared in model A. const USERNAME = ':email_username'; const PASSWORD =…
Alex
  • 673
  • 3
  • 9
  • 22
0
votes
2 answers

PHP class constants seems to always be interpreted as strings

A class constant always seems to be interpreted as a string although it is defined as an integer. Why does PHP do this kind of type juggling and how do I prevent it? See the following code: class BitSet { const NONE = 0; const FOO = 1; const…
user2690527
  • 1,729
  • 1
  • 22
  • 38
0
votes
1 answer

Using const_missing to refer to a class external from the module

I have an app with this folder structure: # /app/controllers/first_controller. class FirstController def method 'External' end end # /app/controllers/second_controller.rb class SecondController def method 'External' end end #…
ProGM
  • 6,949
  • 4
  • 33
  • 52
0
votes
1 answer

mfc c++ getting control properties by control

This may seem that I am asking a silly question to those who already know. Have you ever noticed how hard it is to find these Setting value constants to properties of some MFC control you are just starting to learn. Wouldn't it be nice, if I could…
Michael Murdock
  • 129
  • 1
  • 9