Here is one simple C++ program, if I run this in Visual studio, it
will never give error...But in Mac it gives error.
//-------------------------------------------------- program
---------------------------------
#include <iostream>
class Test
{
private:
public:
void TestIt(Test inObj)
{
Test &newObj = getObj() ; // Gives error here : invalid
initialization of non-const reference of type 'Test&' from a temporary
of type 'Test'
class Test
{
private:
public:
void TestIt(Test inObj)
{
Test &newObj = getObj() ;
}
Test getObj() const
{
Test obj ;
return obj;
}
};
int main (int argc, char * const argv[])
{
Test obj ;
obj.TestIt(obj);
return 0;
}
}
Test getObj() const
{
Test obj ;
return obj;
}
};
int main (int argc, char * const argv[])
{
Test obj ;
obj.TestIt(obj);
return 0;
}
//-------------------------------------------------- End
---------------------------------
Error : invalid initialization of non-const reference of type
Anyone faced this problem?
"opengl" <gururaj...@gmail.com> wrote in message
news:fb088c5f-efd9-47b1...@c37g2000prb.googlegroups.com...
> Hi All,
>
> Here is one simple C++ program, if I run this in Visual studio, it
> will never give error...But in Mac it gives error.
>
> //-------------------------------------------------- program
> ---------------------------------
> #include <iostream>
>
>
> class Test
> {
> private:
>
> public:
> void TestIt(Test inObj)
Try changing this to:
void TestIt( Test& inObj )
see if that fixes it.