Solved

smart pointer

Posted on 2000-04-27
6
285 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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