Solved

How to use operator == overloading and copy constructor in ActiveX control ?

Posted on 2004-04-04
2
303 Views
Last Modified: 2013-11-20
Hi All,
     This question is related to the class shown below. I used the following in the interface file (.idl) for making an ActiveX control in visual c++-

[id(1), helpstring("operator == overloading")] BOOL operator== (const Test& testObj);
[id(2), helpstring("addValue()")] HRESULT addValue(unsigned int value);
...
[id(4), helpstring("Test class copy constructor")] HRESULT Test(const Test& testObj);

While compiling, the compiler gives the error that operator== not allowed and also regarding the use of Test(const Test& ..). I have to use these two methods in making a activex control. Please suggest some method, tips so that I can use all the methods of Test class.
Please reply as quick as possible as it is urgent.

Thanks in advance,
Pawan
//Test class
#include <iostream>
#include <string>
using namespace std;

class Test
{
private:
    unsigned int total;
public:
    Test();
    ~Test();
    Test(const Test& testObj);
    void addValue(unsigned int value);
    unsigned int getValue();
    bool operator== (const Test& testObj);
};

Test::Test()
{
     total = 0;
}
Test::~Test()
{
}

Test::Test(const Test& testObj)
{
    this->total = testObj.total;
}

void Test::addValue(unsigned int value)
{
    total = total + value;
}

unsigned int Test::getValue()
{
    return total;
}

bool Test::operator==(const Test& testObj)
{
    if (this->total == testObj.total)
        return true;
    else
        return false;
0
Comment
Question by:pawantestaccount
2 Comments
 
LVL 16

Accepted Solution

by:
nonubik earned 125 total points
ID: 10755771
As far as I understand, you want to expose the operator== and copy constructor of Test class through some interface (e.g. ITest). An interface does not have a constructor, nor operator overloading. You  can define instead some methods like
HRESULT isEqual (.. , BOOL *pbEqual)
HRESUTL copy(.., Test **ppTest)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
Strange date stored 22 100
tripleUp challenge 7 67
wordmultiple challenge 12 92
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

15 Experts available now in Live!

Get 1:1 Help Now