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\nicholas tse\my documents\c++\handleclass.h(10) : error C2440: 'initializing' : cannot convert from 'class myclass *' to 'class Handle *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2. c:\documents and settings\nicholas tse\my documents\c++\handleclass.h(10) : error C2439: 'handler' : member could not be initialized
c:\documents and settings\nicholas tse\my documents\c++\handleclass.h(8) : see declaration of 'handler'
3. c:\documents and settings\nicholas tse\my documents\c++\handleclass.cpp(14) : error C2039: 'getx' : is not a member of 'Handle'
c:\documents and settings\nicholas tse\my documents\c++\handleclass.h(7) : see declaration of 'Handle'
4. c:\documents and settings\nicholas tse\my documents\c++\handleclass.cpp(15) : error C2039: 'gety' : is not a member of 'Handle'
c:\documents and settings\nicholas tse\my documents\c++\handleclass.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 3123
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.
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |