Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

smart pointer

Posted on 2000-04-27
6
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 20 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

609 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