R
rn
the code below compiles OK with gcc 4.0 but not with gcc.4.2 and visual
studio 2005 (ver 8 ).
to me it seems it should not compile.
-----
class test1
{
public:
friend test1* newtest1(int x)
{
test1* anobj = new test1();
anobj->finishinit(x);
return anobj;
}
virtual ~test1()
{
}
private:
int avalue;
test1()
{
avalue = 0;
}
void finishinit(int x)
{
avalue = x;
}
};
int main(int argc, char *argv[])
{
test1* tobj = newtest1(5);
delete tobj;
}
studio 2005 (ver 8 ).
to me it seems it should not compile.
-----
class test1
{
public:
friend test1* newtest1(int x)
{
test1* anobj = new test1();
anobj->finishinit(x);
return anobj;
}
virtual ~test1()
{
}
private:
int avalue;
test1()
{
avalue = 0;
}
void finishinit(int x)
{
avalue = x;
}
};
int main(int argc, char *argv[])
{
test1* tobj = newtest1(5);
delete tobj;
}