| Date: | Wed, 26 Apr 2006 14:47:38 +0300 | 
| From: | Diomidis Spinellis <dds@aueb.gr> | 
| Organization: | Athens University of Economics and Business | 
| User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060404 SeaMonkey/1.0.1 | 
| MIME-Version: | 1.0 | 
| Newsgroups: | comp.lang.c++ | 
| Subject: | Re: c++ code -- error | 
| References: | <1146048843.472377.165100@t31g2000cwb.googlegroups.com> | 
| In-Reply-To: | <1146048843.472377.165100@t31g2000cwb.googlegroups.com> | 
| Content-Type: | text/plain; charset=ISO-8859-1; format=flowed | 
| Content-Transfer-Encoding: | 7bit | 
Ciur Eugen wrote:
> Could somebody help me in finding error in the following code ?
> 
> 
> 	int ** t; // a table of pointers to int, t[i], is a pointer to int
> 	int i;
> 
> 	t = new int*[10];                // memory allocation
> 	for( i=0 ; i < 10; i++ )
> 	{
> 		t[i] = new int();       // memory allocation
> 	}
Although your code is C++, the style is very close to C (you just 
replaced malloc with new).  You're not benefitting from the modern C++ 
facilities, and getting confused with pointers and memory handling. 
Unless this is an academic exercise, I suggest you look into the 
standard template library (STL) and specifically the vector container.
-- 
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?clcpp
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.