Как работает ключевое слово «const» в C ++?C++

Программы на C++. Форум разработчиков
Anonymous
Как работает ключевое слово «const» в C ++?

Сообщение Anonymous »

Рассмотрим: < /p>

Код: Выделить всё

namespace pairDemo{

template
class pair{
public:

pair(const L& left,const R& right)
:lft(left),rht(right)
{
}

pair(const pair& p)
:lft(p.lft),rht(p.rht)
{
}

L left() const{
return lft;
}
R right() const{
return rht;
}

void left(const L& left){
lft = left;
}
void right(const R& right){
rht = right;
}
private:
L lft;
R rht;
};
}
// ----------------------------------------- -------------- < /p>
#include "pairTemp.h"
#include
using namespace std;

pairDemo::pair func(int x, double y){
pairDemo::pair temp(x*2, x+y);
return temp;
}

int main(){
int x = 2; double y = 3.55;
pairDemo::pair myPair = func(x,y);
cout

Подробнее здесь: https://stackoverflow.com/questions/943 ... -work-in-c

Вернуться в «C++»