?
Solved

new operator

Posted on 2000-04-27
7
Medium Priority
?
248 Views
Last Modified: 2010-04-02
What's the problem with this code???
CPoint **CMyDoc::GetTwoLastPoints()
{
 CPoint **points;
 *points=(CPoint*)new (CPoint*)[2];
 *points=(CPoint*)m_oblPoints.GetTail();
 //Code for second point...
 return points ;
}

//m_oblPoints is CObList
0
Comment
Question by:mdanny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 1

Author Comment

by:mdanny
ID: 2755705
Adjusted points from 10 to 20
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2756522
try then next

CPoint **CMyDoc::GetTwoLastPoints()
{
 CPoint **points;
 points= new (CPoint*)[2];
 points[0]=(CPoint*)m_oblPoints.GetTail();
 //Code for second point...
 return points ;
}

first:it should be
points= new (CPoint*)[2];

scond: it should be
points[0]=(CPoint*)m_oblPoints.GetTail
or
points[1]=(CPoint*)m_oblPoints.GetTail


0
 

Accepted Solution

by:
sambitdash earned 20 total points
ID: 2807502
CPoint **CMyDoc::GetTwoLastPoints()
  {
            CPoint **points;
            points= new (CPoint*)[2];

           // points should be first alloced memory before
          //  it's elements are assigned values else program
          //  will give memory fault

            points[0]=(CPoint*)m_oblPoints.GetTail();
            points[1]=(CPoint*)m_oblPoints.GetTail ();

            return points ;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:mdanny
ID: 2849183
Answer accepted
0
 
LVL 1

Author Comment

by:mdanny
ID: 2849184
the answer is
points= new CPoint*[2];

           
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2850424
can i ask you why did you accepted his answer?
just for knowing i don't see much diffrence in his answer from my comment
0
 
LVL 1

Author Comment

by:mdanny
ID: 2853447
I can give you points also.I'll post a q for you
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question