Why this can't compile:
// RefToPointers.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using std::cout;
class T
{
public:
T(int* value):data_(value)
{
}
int* data_;
int* getData_()
{
return data_;
}
int getValue()//<----------Here I do not return by ref
{
return *data_;
}
};
void fnc(const int*& left, const int*& right )//<------Doesn't work even though
//it is identical to the example below just type is different. Why?
{
const int* tmp = left;
left = right;
right = tmp;
}
void fnc(const int& left,const int& right)//<---Here I pass by ref
{
}
int _tmain(int argc, _TCHAR* argv[])
{
//int* one = new int(1);
//int* two = new int(2);
//cout << "Pointers before change:" << *one << '\t' << *two << '\n';
//fnc(one,two);
//cout << "Pointers before change:" << *one << '\t' << *two << '\n';
T one(new int(1));
T two(new int(2));
fnc(one.getData_(),two.getData_());//<---This do not work
fnc(one.getValue(),two.getValue());//<<------This still works even thoug I'm
//returning by value and fnc is taking args by ref. Why does it work with int
//by not with int*?
return 0;
}
I'm getting following error:
_error C2664: 'fnc' : cannot convert parameter 1 from 'int *' to 'int *&_
And why on earth underscores do not make font italic in line where error is listed?