[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [linux-india-programmers] C++ question



Hi,
  You are assigning ptr the address of the object c.(cast as an int)
Hence you are accessing the memory directly.This (kind of) violates
the OOPS philosophy.One of the reasons Java doesen't have pointers......

BTW, does any one have any documentation,references or resources on the
web (online papers, books etc.) regarding gcc internals and the data
structures used in gcc 2.95.2.(other than the original gcc manuals
"Using and porting GNU CC").

  Help would be most deeply appreciated

                           Regards,
  			  Deepak Chandrashekar

On Thu, 6 Jul 2000, G Gautam wrote:

> Hi,
> 
> This isn't a linux question but it does happen with g++. So that's why I have posted here.
> 
> #include<iostream.h>
> 
> class tmp
> {
> 	   private:
> 			   int var;
> 	   public:
> 			   void set( int i )
> 			   {
> 					   var = i;
> 			   };
> };
> 
> main()
> {
> 		int *ptr;
> 		tmp c;
> 
> 		c.set( 200 );
> 		ptr = ( int* ) &c;
> 
> 		cout << *ptr;
> 		return 0;
> }
> 
> I really should not be seeing the value of var, right? I would appreciate any feedback.
> 
> Thanks
> Gautam
> 
> ------------------------------------------------------------------------
> Who invented Gatorade -- and what part did it play in
> winning the1967 Orange Bowl? Find out the true facts at
> http://click.egroups.com/1/6212/8/_/30164/_/962898033/
> ------------------------------------------------------------------------
>