Hi, I want to define an structure, where some math constants would be stored.
Here what I've got now:
struct consts {
//salt density kg/m3
static const double gamma;
};
const double consts::gamma = 2350;
It works fine, but there would be more than 10 floating point constants, so I doesn't want to wrote 'static const' before ...
The C++ standard mandates that all conforming implementations support the following two signatures for main:
int main();
int main(int, char*[]);
In case of the latter signature, would the addition of (top-level) const-ness break any language rules?
For example:
int main(const int argc, char** const argv);
From my understanding, t...
Hi,
I want to const declare the this pointer received as an argument.
static void Class::func(const OtherClass *otherClass)
{
// use otherClass pointer to read, but not write to it.
}
It is being called like this:
void OtherClass::func()
{
Class::func(this);
}
This does not compile nad if i dont const declare the OtherCla...
I have a simple function Bar that uses a set of values from a data set that is passed in in the form of an Array of data structures. The data can come from two sources: a constant initialized array of default values, or a dynamically updated cache.
The calling function determines which data is used and should be passed to Bar.
Bar does...
I want to use a vector to hold read-only integer-matrices of the size 5x5
vector<const int[5][5]> startingPieces;
But this declaration causes a bunch of weird errors I've never ever seen before.
error C2535: 'const int (*std::allocator<_Ty>::address(const int (&)[5][5]) const)[5][5]' : member function already defined or declared
1> ...
So in C# I create something like
private const int HEADER_LENGTH = 13;
private const byte SIGNATURE1 = 0x46;
How to create its analog in PHP?
...
Hello all,
I tried to search the site for this question but didn't find this exactly, although this subject is being discussed a lot...
I have this declaration in a cpp file, not within any function:
static const char* gText = "xxxxxxxxxxx";
Although it has a fixed size, I get a warning from a static analysis tool (Klocwork) when I'm...
Hi,
given the following code:
/* signatures */
int getParams(char params[MAX_PARAM_LEN][MAX_LINE_LEN]);
int getVersion(const char params[MAX_PARAM_LEN][MAX_LINE_LEN],
const char* tagName );
/* initializing */
char params[MAX_PARAM_LEN][MAX_LINE_LEN] = {};
/* getting parameters */
paramCount = getParams(params); /* OK, p...
We all know that things like this are valid in c++:
const T &x = T();
while:
T &x = T();
is not.
In a recent question the conversation lead to this rule. The OP had posted some code which clearly evokes UB. But I would have expect a modified version of it to work (This is the modified version):
#include <iostream>
using namespace...
I have a variable which is the head to a linked list. I want to make it const because it should never be changed, the variable is used throughout the program, so I thought I should make it a global const. The problem is that I couldn't initialize it after I declared it const.
How can I get around this problem?
typedef struct PT {
...
Clearly, declaring a local variable as const, prevents runtime modification. Const instance variables are static (I believe). Does this have any bearing on the nature and use of const local variables? (e.g. threading)
...
Possible Duplicate:
Meaning of const last in a C++ method declaration?
Hi
I got a book, where there is written something like:
class Foo
{
public:
int Bar(int random_arg) const
{
// code
}
};
Also, a by-the-way question: why should/shouldn't I use const before argument declarations? What does that chang...
In C# and Java, it's possible to create constant strings using one or more other constant strings. I'm trying to achieve the same result in C++ (actually, in C++0x, to be specific), but have no idea what syntax I would use to achieve it, if such a thing is possible in C++. Here's an example illustrating what I want to do:
#include <st...
I am reading a book called 'Effective C++, Second Edition' and its talking about const member functions and how you have bitwise const-ness and conceptual const-ness.
It says most compilers will go with bitwise const-ness, which is that you cannot alter data members of an object inside a const member function.
Then there's an example o...
Is there a way to make a non-resizeable vector/array of non-reassignable but mutable members? The closest thing I can imagine is using a vector<T *> const copy constructed from a temporary, but since I know at initialization how many of and exactly what I want, I'd much rather have a block of objects than pointers. Is anything like wha...
How do I force const-ness of the memory pointed to by obj->val1 in the function fn?
#include <iostream>
struct foo {
int* val1;
int* val2;
int* val3;
};
void fn( const foo* obj )
{
// I don't want to be able to change the integer that val1 points to
//obj->val1 = new int[20]; // I can't change the pointer,
*...
Subj. I'd like to use strings instead of PChar because that spares me much casting, but if I just do
procedure SomeExternalProc(s: string); external SOMEDLL_DLL;
and then implement it in some other project with non-shared memory manager:
library SeparateDll;
procedure SomeExternalProc(s: string);
begin
//a bla bla bla
//code here...
I'm trying to pass a build number from Hudson into a Flex application.
I've found Adobe's document (http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html) on conditional compilation which seems it should solve it but i must be missing something.
So in my ant build file i have:-
<mxmlc
file="${app.dir}/${app...
If I have a class that contains only compile-time constants, for example,
class A {
static const int x = 1;
static const int y = 2;
static const int z = 3;
};
I believe it's the case that, so long as the address of the constants is not taken, they can (will?) be replaced at compile time where they are used and will not tak...
What is the difference between:
const variable = 10;
and
const int variable = 10;
Does variable, per the standard, get interpreted as an integral type when no type is defined?
...