1-) I think you mean const and not "Const"
The first const tell that the function will be used when the class is const. And the one at the end tell that is a read only function.
This is an example
Code: Select all
#include <iostream>
using namespace std;
class ClassA
{
public:
int nValue;
ClassA() {nValue=1;}
};
class ClassTest
{
public:
ClassTest() {Variable1=0;}
const int func1(const ClassA& A) const { return A.nValue;}
int func1(const ClassA& A) {Variable1=2; return A.nValue;}
int Variable1;
};
int main(void)
{
const ClassA MyA;
const ClassTest MyTest;
ClassTest MyTest2;
cout << "=== MyTest" << endl;
cout << "nValue = "<< MyTest.func1(MyA) << endl;
cout << "Variable1 =" << MyTest.Variable1 << endl;
cout << "=== MyTest2" << endl;
cout << "nValue = "<< MyTest2.func1(MyA) << endl;
cout << "Variable1 =" << MyTest2.Variable1 << endl;
return 0;
}
And this is the output
Code: Select all
pi@WebPi ~ $ g++ -o test test.cpp
pi@WebPi ~ $ ./test
=== MyTest
nValue = 1
Variable1 =0
=== MyTest2
nValue = 1
Variable1 =2
2-) Integer template could pass parameters
http://stackoverflow.com/questions/4991 ... int-n-mean
your example are hard to decipher since you just put one line.
I hope it helps
Daniel