|
Friday, April 07, 2006 - 5 Posts by 3 People
Hi,
Code: Select all // vector add
const CVector operator+(const CVector &vec) const
{
return
CVector(x + vec.x, y + vec.y, z + vec.z);
}
could someone please explain what each of the three consts
1st const:
The object-result of overloaded operator has const attribute. That is, it cannot
|
|
Friday, January 02, 2009 - 11 Posts by 11 People
Hi,
I need to call a const function from a non-const object. See example
struct IProcess { virtual
bool doSomeWork() const = 0L; }; class Foo : public IProcess { virtual bool doSomeWork() const
You don't have to do any casting trickery if the function is not overloaded. Calling a const method
|
|
Sunday, April 19, 2009 - 3 Posts by 3 People
I have code like this:
NSData *data = [NSData dataWithContentsOfURL:objURL]; const void *buffer
like:
- (void)_loadData:(const char *)data;
How do I convert "const void " to a "const char
Just like you would in C:
[self _loadData:(const char *)buffer];
should work.
You mustn't release
|
|
Sunday, April 19, 2009 - 11 Posts by 11 People
As an extension to this question Are const_iterators faster? , I have another question on const
_iterators . How to remove constness of a const_iterator ? Though iterators are generalised form
You can subtract the begin() iterator from the const_iterator to obtain the position the const
|
|
Wednesday, August 26, 2009 - 13 Posts by 13 People
While striving for const-correctness, I often find myself writing code such as this
class Bar
; class Foo { public: const Bar* bar() const { /* code that gets a Bar somewhere */ } Bar* bar() { return
You can do something like this:
class Bar; class Foo { public: const Bar* bar() const { return
|
|
Friday, July 31, 2009 - 6 Posts by 6 People
The lack of const identifiers (I forgot them, but now I want to know why this won't work). I am
trying to get this to compile:
Node(Node const& other) : prev_(other.prev()), value_(other.value
You're not trying to do a non-const to const conversion. You're attempting to call two methods
|
|
Wednesday, May 13, 2009 - 8 Posts by 8 People
Non-trivial chunk of code... return something; } const Something& getSomething(int index) const
with the other one, because you can't call the non-const version from the const version (compiler
I would cast the const to the non-const (second option).
Try to eliminate the getters
|
|
Monday, October 26, 2009 - 6 Posts by 6 People
Is there a difference in the order of the comparison operator?
#define CONST_VALUE 5 int variable
; ... if ( variable == CONST_VALUE ) // Method 1 ... OR if ( CONST_VALUE == variable ) // Method 2
, static analysis of the code).
The only difference is that ( CONST_VALUE == variable ) makes the common
|
|
Thursday, May 11, 2006 - 3 Posts
I'm a little confused. I have a class function declared like:
const CItem& operator << (const
,...,0,0,20,0,0,20,eol";
At the end of the method it does:
return *this;
My question is, is my const on the return...
;
> const CItem& operator << (const std::string &sIn);
>
> Which I use like this:
>
|
|
Sunday, January 04, 2009 - 4 Posts by 4 People
I am trying to do the following in a way or another:
const char EscapeChar = '\\'; const string
it to be a const instead of static readonly ? The latter will have almost the same semantics.
The only ways
I can think of (both not ideal) are:
const string EscapeString = "\\"; private static readonly
|

)