Hello all C++ expert programmer,
I have a handle class which point to another class and use the pointer as object.
I follow the code from C++ articles submited by someone in this forum. Unfortunately, my compilation is failed.
Below is my code : -
// Main.cpp
-
-
#include<iostream>
-
#include "myclass.h"
-
#include "HandleClass.h"
-
-
using namespace std;
-
-
-
int main(int argc, char *argv[])
-
{
-
Handle aHandler(3, 4);
-
-
aHandler->getx();
-
aHandler->gety();
-
-
return 0;
-
}
-
-
Heade File : -
// Handle Class
-
-
#ifndef _myclass_
-
#define _myclass_
-
-
class myclass
-
{
-
int x, y;
-
-
public:
-
myclass() : x(0), y(0){}
-
myclass(int user1, int user2) : x(user1), y(user2){}
-
-
~myclass(){}
-
-
void getx(){std::cout << "X is " << x;}
-
void gety(){std::cout << "Y is " << y;}
-
};
-
-
#endif
-
-
Header File : -
// Handle to class
-
-
#ifndef _Handle_
-
#define _Handle_
-
-
class Handle
-
{
-
Handle *handler;
-
public:
-
Handle(int user1, int user2) : handler(new myclass(user1, user2)){}
-
Handle *operator->(){return handler;}
-
-
~Handle(){delete handler;}
-
-
};
-
-
#endif
-
-
Error Message is :
1. c:\documents and settings\nichol as tse\my documents\c++\h andleclass.h(10 ) : error C2440: 'initializing' : cannot convert from 'class myclass *' to 'class Handle *'
Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
2. c:\documents and settings\nichol as tse\my documents\c++\h andleclass.h(10 ) : error C2439: 'handler' : member could not be initialized
c:\documents and settings\nichol as tse\my documents\c++\h andleclass.h(8) : see declaration of 'handler'
3. c:\documents and settings\nichol as tse\my documents\c++\h andleclass.cpp( 14) : error C2039: 'getx' : is not a member of 'Handle'
c:\documents and settings\nichol as tse\my documents\c++\h andleclass.h(7) : see declaration of 'Handle'
4. c:\documents and settings\nichol as tse\my documents\c++\h andleclass.cpp( 15) : error C2039: 'gety' : is not a member of 'Handle'
c:\documents and settings\nichol as tse\my documents\c++\h andleclass.h(7) : see declaration of 'Handle'
These are all the errors i got from the compiler.
Thaks for your help.
Your help is greatly appreciated by me and others.
3 3152 AdrianH 1,251
Recognized Expert Top Contributor
Hello all C++ expert programmer,
I have a handle class which point to another class and use the pointer as object.
I follow the code from C++ articles submited by someone in this forum. Unfortunately, my compilation is failed.
Below is my code : -
// Main.cpp
-
-
#include<iostream>
-
#include "myclass.h"
-
#include "HandleClass.h"
-
-
using namespace std;
-
-
-
int main(int argc, char *argv[])
-
{
-
Handle aHandler(3, 4);
-
-
aHandler->getx();
-
aHandler->gety();
-
-
return 0;
-
}
-
-
Heade File : -
// Handle Class
-
-
#ifndef _myclass_
-
#define _myclass_
-
-
class myclass
-
{
-
int x, y;
-
-
public:
-
myclass() : x(0), y(0){}
-
myclass(int user1, int user2) : x(user1), y(user2){}
-
-
~myclass(){}
-
-
void getx(){std::cout << "X is " << x;}
-
void gety(){std::cout << "Y is " << y;}
-
};
-
-
#endif
-
-
Header File : -
// Handle to class
-
-
#ifndef _Handle_
-
#define _Handle_
-
-
class Handle
-
{
-
Handle *handler;
-
public:
-
Handle(int user1, int user2) : handler(new myclass(user1, user2)){}
-
Handle *operator->(){return handler;}
-
-
~Handle(){delete handler;}
-
-
};
-
-
#endif
-
-
Error Message is :
These are all the errors i got from the compiler.
Thaks for your help.
Your help is greatly appreciated by me and others.
It is quite simple, look at line 10 in file handleclass.h, then look at the message. myclass is not a Handle so you cannot assign a myclass pointer to it.
Adrian
Then how to solve it. I have no idea what is handle class.
Thanks for your help.
Your help is greatly appreciated by me and others.
JosAH 11,448
Recognized Expert MVP
Hello all C++ expert programmer,
I have a handle class which point to another class and use the pointer as object.
I follow the code from C++ articles submited by someone in this forum. Unfortunately, my compilation is failed.
Have a look at the C/C++ Articles section; it has a nice article about just this:
handle classes; the article even explains reference counting handle classes or
'fat pointers' or 'smart pointers'.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tony Johansson |
last post by:
Hello!!
Assume I have a handle body pattern with classes called Handle and Body.
In the Body class I store one int value for example 7 or some other integer
value.
In the Handle class I have a pointer to the Body class.
If a want to create a STL container of List with the following
declaration List <Handle <Body> > list
|
by: Tony Johansson |
last post by:
Hello!
Here I have two classes these are called Handle and Body and a main. You
have the class definition below.
Some basic information. In the Handle class is there a pointer to the Body.
Each Body object contains one primitive datatype int.
The Body instance is created in the constructor for Handle. In main I
instansiate some Handle object and use the STL function push_front to push
these object into the list.
|
by: Indiana Epilepsy and Child Neurology |
last post by:
Before asking this questions I've spent literally _years_ reading
(Meyer, Stroustrup, Holub), googling, asking more general design
questions, and just plain thinking about it. I am truly unable to
figure out what would be a "proper" OO design (in C++) for this.
There may be alternatives to writing my own ODBC handle classes, and I
may be interested in them, but I'd like to pursue this particular
problem, if for no other reason than to...
|
by: Leandro Berti via DotNetMonster.com |
last post by:
Hi All,
I wrote a code to do serial communication with an equipament.
When i use the code outside of threaded class it seens work properly,
but when i put inside a class and execute a thread in the first seconds the
communication is ok, later i receive read/write error.
I?ve been in MSDN site and there i discover that the read/write error is a
INVALID_HANDLE problem. But why??? I just create the serial communication
file and use it....
|
by: SamSpade |
last post by:
If I have a class that inherits from, say RichTextBox and in the derived
class I refer to Handle, does it refer to the RichTextBox class or the
derived class?
I'm wondering if the derived class gets it's own handle or is there only one
for both classes (after all there is only one window)?
Thanks
| |
by: Gary Wessle |
last post by:
Hi
I need help organizing this program in the right way.
I included the code below which compiles and runs and gives the
desired effect to a certain point, but I don't know what the next step
is to finish this program.
the program presents Main menu to the user and gives a prompt, the
user types the number corresponding to an item from the menu, the
program then
|
by: Liming |
last post by:
Hi,
In a typical 3 tier model (view layer, busines layer and data access
layer) where do you handle your exceptions? do you let it buble up all
the way to the .aspx pages or do you handle it in your business layer
and/or data access layer?
suppose in my data access layer, I provide try and catch, log the
exception and re-throw it back to business layer, then in yoru business
layer, what do you do? throw it back to the code behind or...
|
by: weaknessforcats |
last post by:
Handle Classes
Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the implementation so the two can vary independently.
Handle classes usually contain a pointer to the object implementation. The Handle object is used rather than the implemented object. This leaves the implemented object free to change without affecting...
|
by: Donos |
last post by:
Hi
I have a HANDLE to an Event, like this..
HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL);
This is running in one thread in one class. For example we will call
that class as "Class A"
Now i want to use this HANDLE in another thread in another class to
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |