From: Ankit on
Hello All,

I have code like this:
Class2 Class1::func (char* response)
{
printf( response);
Class2* d_ = new Class2;
d_->func (response);
//print response within Class2->func prints the response
return d_;
}


Snippet of Class2:
Class2 {
//constructor & destructor
void func(char*);


};

Above code works perfectly well on Windows. But not working in Solaris
x86 v10g. with CC compiler 12with patch.
On solaris if I try to print the response within Class2, it doesnt
prints the content of char* passed as input parameter.




From: Paul Floyd on
On Fri, 21 May 2010 09:13:53 -0700 (PDT), Ankit <ankit.kr85(a)gmail.com> wrote:
> Hello All,
>
> I have code like this:
> Class2 Class1::func (char* response)
> {
> printf( response);
> Class2* d_ = new Class2;
> d_->func (response);
> //print response within Class2->func prints the response
> return d_;
> }
>
>
> Snippet of Class2:
> Class2 {
> //constructor & destructor
> void func(char*);
>
>
> };
>
> Above code works perfectly well on Windows. But not working in Solaris
> x86 v10g. with CC compiler 12with patch.
> On solaris if I try to print the response within Class2, it doesnt
> prints the content of char* passed as input parameter.

If you want real help, then you'll need to reduce this to a small
example that you can post and we can compile and check.

Just looking at your code it is clear to me that it should not compile.

Class2 Class1::func (char* response)
{
Class2* d_;
return d_;
}

Just this extract, member function that returns a Class2 object, but the
return statement returns a Class2 _pointer_.

Also
printf( response);

is very bad. You should _always_ provide a format string for printf and
scanf family functions. If response contains any formatting characters,
then your application may produce incorrect results, crash or even be
a security risk.

printf("%s", response);

Even better in C++ would be to use a string class and insertion
operators.

For instance:

Class2* Class1::func(const std::string& response)
{
std::cout << response;
Class2* d_ = new Class2;
d_->func (response);
return d_;
}

A bientot
Paul
--
Paul Floyd http://paulf.free.fr