|
I am trying to play fancy games which have the C++ compiler synthesize hash values of constant strings at compiletime. This would let me replace the string with a single identifier, with a massive savings in code size and complexity.
For programming clarity...
Started by SPWorley on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
I exploited that fact; printer(); return 0; }
The relevant difference here is the difference between a "Integral Constant Expression" and a mere compile-time....
That the compiler optimiser does treat it as a character constant, pretty much.
|
|
I am trying to define a constant BUFFER_LENGTH for my class for a given usecase.
//1. Using preprocessor declaration //#define BUFFER_LENGTH 12 //2.Global constant //const int BUFFER_LENGTH = 12; class MyRequest { public: //3. Define an in-class constant...
Started by aJ on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Read the constant out of the....
If the constant's meaning is entangled with the class, I would define to e.g.
An enumerate type is not meant to define a numeric constant, though it's (ab)used for that a lot in template-metaprogramming.
|
|
I'm using constants for output messages in different languages. For example, if a user chooses "English", a file with this constant would be required:
define('welcomeMessage','Welcome!');
If she chooses "Spanish":
define('welcomeMessage','Bien Venidos...
Started by Gal on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I would.
It doesn't make sense to use a constant if the value can be changed later.
With define() ).
|
Ask your Facebook Friends
|
Hello. I'm learning C++ and I'm still confused about this. What are the implications of return a value as constant, reference and constant reference in C++ ? For example:
const int exampleOne(); int& exampleTwo(); const int& exampleThree();
Answer Snippets (Read the full thread at stackoverflow):
Returning a constant value isn't a very common idiom, since you're;a; return this->a; } //return ....
They do not affect performance.
A particular instance of an object, and you understand the lifetime of the object Const / Constant.
|
|
Here is part of my code
define('DIR_APP', 'app/'); class Questions { const QUESTIONS_FILE = DIR_APP . 'questions.xml'; }
Seems when I take the define()'d constant out of my class constant declaration, it works fine. But when I add it it throws this error...
Started by alex on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
'questions.xml';
It can't be a constant expression, not (for example) a variable, a class member, result of a mathematical.
Const QUESTIONS_FILE = constant("DIR_APP") .
About trying this though...
|
|
I want to use a constant in php, but i also want to put it inside double quotes like a variable. Is this at all possible?
define("TESTER", "World!"); echo "Hello, TESTER";
obviously outputs "Hello, TESTER", but what I really want is something like:
$tester...
Started by contagious on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Use concatenation...?
I've found that when dot-concatenation of a constant is a problem, using use a double quotes string the php can to process slowly; You don't use a constant into a string, because don't have any delimiter to the php....
|
|
Class My_class { const STATUS_ERROR = 0; const STATUS_OK = 1; const DB_TABLE = TABLE_PREFIX . 'class_table'; }
The two status consts work fine and can be accessed within class methods as self::STATUS_ERROR and self::STATUS_OK just fine.
The issue is one...
Started by Matt on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You can use a static property be defined with a constant value, they can't be the result of an expression
http://www.phpbuilder.com.
You can't store anything in them.
Constants are constant.
You don't.
|
|
I have some existing code that I've used to write out an image to a bitmap file. One of the lines of code looks like this:
bfh.bfType='MB';
I think I probably copied that from somewhere. One of the other devs says to me "that doesn't look right, isn't...
Started by 1800 INFORMATION on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
It probably depends.
Statement -- it's just a different way of expressing an integer constant.
|
|
I have a number of icons used throughout an application - let's take ok/cancel icons as an example. At the moment they might be a tick and a cross (tick.png, cross.png) but I may want to replace them in future. Also, I would like to keep the resource ...
Started by Draemon on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Leave.
This way, you would only have to declare a new Icon constant, and the corresponding resource would be loaded automatically based on the name of the constant.
Public static Icon field in the class.
|
|
I want to do something like this:
const MyFirstConstArray: array[0..1] of string = ('Hi', 'Foo'); MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string = MyFirstConstArray + ('Bar');
Basically I want the following result:
MyFirstConstArray...
Started by Fabio Gomes on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Is to ensure you declare your actual constant string only once, I suggest you declare the individual.
|