Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Smart Pointer p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 12 Topic 9747 of 9909
Post > Topic >>

Smart Pointer problem

by Saurabh Gupta <subscription.gupta@[EMAIL PROTECTED] > Jun 26, 2008 at 01:22 PM

{ Please avoid too long lines; it's best to limit your text to
   70 columns or so, less than 80 at least. In addition, please consider
   using a charset that fits the English environment better, such as
   US-ASCII or ISO-8859-*. -mod }

We have our smart pointer implementation. But the operator -> is
creating problem in case of a const pointer. It's always returning a
non-const pointer, therefore, we are able to call a non const function
on a const pointer. How can we overcome this problem?
Smart pointer code.

       /**
      *  Returns the raw pointer for use in calling member functions.
      */
       T *operator->() const
       {
             return m_p;
       }

Sample Code:

class Test {
public:
	void ChangeData(int a, int b)
	{
		X = a;
                 Y = b;
	}
private:
	int x;
	int y;
};
typedef CC::CSmartPointer<Test> TestPtr;

Void TestData(const TestPtr& test)
{
                // here. We should get the compilation error. But it’s
working fine due to behavior of
                //the Smart Pointer operator -> .

              test->ChangeData(x, y);
}


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 12 Posts in Topic:
Smart Pointer problem
Saurabh Gupta <subscri  2008-06-26 13:22:26 
Re: Smart Pointer problem
Maciej Sobczak <see.my  2008-06-27 14:07:29 
Re: Smart Pointer problem
Greg Herlihy <greghe@[  2008-06-27 14:10:54 
Re: Smart Pointer problem
"Alf P. Steinbach&qu  2008-06-27 14:14:44 
Re: Smart Pointer problem
Ulrich Eckhardt <eckha  2008-06-27 14:15:29 
Re: Smart Pointer problem
Markus Moll <markus.mo  2008-06-27 14:24:16 
Re: Smart Pointer problem
Mathias Gaunard <loufo  2008-06-27 14:27:57 
Re: Smart Pointer problem
ppi <vodoom@[EMAIL PRO  2008-06-27 14:28:00 
Re: Smart Pointer problem
Martin Bonner <martinf  2008-06-27 14:27:58 
Re: Smart Pointer problem
Oncaphillis <oncaphill  2008-06-27 14:28:00 
Re: Smart Pointer problem
Ruki <waruqi@[EMAIL PR  2008-06-27 14:27:56 
Re: Smart Pointer problem
wasti.redl@[EMAIL PROTECT  2008-06-27 14:29:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 13:07:39 CDT 2008.