Solved

smart pointer

Posted on 2000-04-27
6
283 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
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

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

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

Suggested Solutions

Title # Comments Views Activity
how to become programmer? 12 33
VS2015 compilation and missing DLLs 9 119
convert char array to number in c 5 83
What is sub-make ? 2 40
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

22 Experts available now in Live!

Get 1:1 Help Now