Solved

smart pointer

Posted on 2000-04-27
6
284 Views
Last Modified: 2013-12-14

The below program is giving linker error . I am using VC++ editor.

#include <iostream.h>

class X{

public:
       int m;
       void Display()
       {
             cout<<m<<endl;
       }
};

class smart{

       int s;

public:
 X* operator ->();
};

void main()
{

      smart pt;
      pt->X::m =10;
      pt->X::Display();
}
 

let me what is the problem.

bye

Arora
0
Comment
Question by:Arora
6 Comments
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2755358
Where's the implementation of the operator-> method? What is the link error?
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2755359
What is the text of the linker error?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2755510
As mnewton has pointed out you have a declaration for smart::operator->(), but you have no definition for it.  If you try to use this function, which you do, you will get a linker error.

You need to write a definition for this function.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Expert Comment

by:ntdragon
ID: 2756556
pt->X::m =10;
pt->X::Display();

what the idea of it???
operator -> should return X* <not X>
and as you wrote it it doesn't take any parameters
0
 

Accepted Solution

by:
sambitdash earned 10 total points
ID: 2807520
You have not implemented the method for
operator X* operator ->() hence the linker error.



                      #include <iostream.h>

                      class X{

                      public:
                      int m;
                      void Display()
                      {
                      cout<<m<<endl;
                      }
                      };

                      class smart{

                      int s;
       X* x;
                      public:
                       smart(X* x1):x(x1){}
                       X* operator ->(){
            return x;
      }
                      };

                      void main()
                      {
      X* x = new X;
                      smart pt(x);
                      pt->X::m =10;
                      pt->X::Display();
                      }
0
 
LVL 22

Expert Comment

by:nietod
ID: 2807609
sambitash, did you read the question history?  This has already been pointed out by mnewton.  You should not answer a question using information or ideas previously posted by another expert, that is like plagerism.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

776 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