Solved

smart pointer

Posted on 2000-04-27
6
282 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

759 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

18 Experts available now in Live!

Get 1:1 Help Now