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

x
?
Solved

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

Posted on 2004-04-04
2
Medium Priority
?
326 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
[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
2 Comments
 
LVL 16

Accepted Solution

by:
nonubik earned 375 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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