Solved

new operator

Posted on 2000-04-27
7
209 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now