Was tryin out the stackeroverflow qn so it got me thinking why not overload the the function and I came up with a slightly different code but it says the function cannot be overloaded. My question is why? or is there a another way?
#include <iostream>
using std::cout;
class Test {
public:
Test(){ }
int foo...
What is the difference between the arguments in:
int foo1(const Fred &arg) {
...
}
and
int foo2(Fred const &arg) {
...
}
?
I don't see this case covered in the parashift FAQ.
...
class a
{
protected:
const int _ID;
public:
a::a(int id){};
a::top(int num);
};
class b : public a
{
static int ok;
b::b(int id):a(id){};
a::top(ok);
}
int main()
{
int t=5;
b opj=b(t);
}
first why i get this compile error that solved only when i remove the const
non-static const member ‘const int Student::_ID’, can...
Possible Duplicate:
Is there some ninja trick to make a variable constant after its declaration?
Consider the following minimal example:
void MutateData(std::string&);
int main()
{
std::string data = "something that makes sense to humans.";
::MutateData(data); // Mutates 'data' -- e.g., only changes the order of the cha...
hello i have an error with the following code:
in my h file i got the following vector:
vector<Vehicale*> m_vehicalesVector;
and in my cpp file i got the following function:
void Adjutancy:: AddVehicale(const Vehicale* vehicaleToAdd)
{
m_vehicalesVector.push_back(vehicaleToAdd);
}
seems like the const Vehicale* vehicaleToAdd is...
I was reading this question here here regarding const-correctness. The Scott Meyer solution seems like a good work-around, but what if you have a member function (which requires both a const and non-const version) that makes use of the this pointer. If the member function is const then this automatically means const this, which can mak...
Okay, I am having trouble with the following piece of code (in a header file):
#ifndef XML_H_INCLUDED
#define XML_H_INCLUDED
#include "libxml/parser.h"
#include "libxml/xmlwriter.h"
#include <string>
class XmlFile{
public:
XmlFile(string filename){
file = xmlParseFile(filename);
}
xmlDocPtr file; //Pointer to xml...
I first store the 3 value into a pair of map like this:
void AddMenuAtlasTexture( int tag, const char* filename, const char* textureName )
{
map<const char*, const char*> _item;
_item.insert(pair<const char*, const char*>(filename, textureName));
m_texturesToLoad.insert(pair<int, map<const char*, const char*> >(tag, _item));
};
th...
I heard the temporary objects can only be assigned to constant references.
But this code gives error
#include <iostream.h>
template<class t>
t const& check(){
return t(); //return a temporary object
}
int main(int argc, char** argv){
const int &resCheck = check<int>(); /* fine */
typedef int& ref;
const ref error = check<int...
Hi,
here is my question I have this in my .h file
static const char *Title[];
How do I initialize the array in my .C file the array to lets say "first", "second", "third"
...
I have an object:
map<A*, string> collection;
I would like to call the map::find function, but the value I have for the key is const, like in the following code, which does not compile:
const A* a = whatever();
collection.find(a);
The following code works and performs the equivalent of the find operation:
const A* a = whatever();
...
Coming from a c++ background, I'm used to sticking the const keyword into function definitions to make the object being passed in a read-only value. However, this is not possible in C#, as I found out (please correct me if I'm wrong). So, after some googling, I came to the conclusion that the only way to make a read only object is to wri...
Hi,
I have this code that tries to protect the user from array boundary errors.
I don't get why this will compile, tho i've declared the array to be const, therefore, i'm suppose to get a compilation error!
thanks a lot.
/************ file: SafeAccessArray.h ********************/
template<typename T>
class SafeAccessArray
{
private:
i...
I have read Answers to C++ interview questions among which there is one that puzzles me:
Q: When are temporary variables created by C++ compiler?
A: Provided that function parameter is a "const reference", compiler generates temporary variable in following 2 ways.
a) The actual argument is the correct type, but it isn't Lv...
In C++. I can declare most things as const, for example:
Variables: const int i=5;
Scala has val i=5, however this will only prevent reassigning, not changing the object as the following exampe shows:
C++: const int i[]={1,2,3,4};
i[2]=5; //error
Scala: val a=Array(1,2,3,4)
a(2)=5 //a is now Array(1, 2, 5, 4)
It gets even worse with mem...
I understand the behavior of const-qualified data types. I am curious, though, if there is any performance gain or loss from over- or under-zealousness of qualifying variables as const. I am thinking particularly of variables declared and used exclusively within an isolated code block. For example, something like:
const qreal padding = ...
How can i list all the names (and values) of public (and private / protected) const defined in a class ?
public class Layers {
public const BACKGROUND:String = "background";
public const PARENT:String = "parent";
public const MAP:String = "map";
public const LINES:String = "lines";
public const POINTS:String = "poin...
Hi all,
I have code like this:
bool doSomething()
{
std::cout << "I'm here!"
return true;
}
const bool x = doSomething();
If placed in a cpp-file in my Visual C++ console application, the code is executed as expected before entering the main() method.
However, if I place this code in a .cpp-file inside a static link library pro...
Hi,
Consider the following:
int a[2];
cin >> a[0] >> a[1];
const int D = a[1] - a[0];
cout << D << "\n";
a[1] = 5; a[0] = 2;
cout << D << "\n";
I'm a bit confused now. Why does it print the same value for D? Why doesn't changing the array values change the value of D? At what point in time is the value of D determined and stored?...
I apologize if this has been asked, but how do I create a member function in c++ that returns a pointer in the following scenerios:
1. The returned pointer is constant, but the junk inside can be modified.
2. The junk inside is constant but the returned pointer can be modified.
3. Neither the junk, nor the pointer can be modified.
Is i...