473,881 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: going crazy with a proxy class...

Hi, I'm trying to learn proxy classes in C++ so I've written the
following code, trying to modify an example given in Deitel & Deitel's
C++ book.
I am trying to "hide" details of the original class (employee.h)
through a proxy class (employeeproxy. h).
What am I doing wrong? Please help... I will be grateful forever.

// Employee class definition.

#include <iostream>
#include <cstring>
using namespace std;
class Employee {

Employee( const char * first, const char *last )
firstName = new char[ strlen( first ) + 1 ];
strcpy( firstName, first );

lastName = new char[ strlen( last ) + 1 ];
strcpy( lastName, last );

++count; // increment static count of employees

cout << "Employee constructor for " << firstName
<< ' ' << lastName << " called." << endl;

}; // end Employee constructor
cout << "~Employee( ) called for " << firstName
<< ' ' << lastName << endl;

delete [] firstName; // recapture memory
delete [] lastName; // recapture memory

--count; // decrement static count of employees

}; // destructor
const char *getFirstName() const
return firstName;

const char *getLastName() const
return lastName;

// static member function
static int getCount()
return count;

}; // return # objects instantiated
char *firstName;
char *lastName;

// static data member
static int count; // number of objects instantiated

}; // end class Employee

int Employee::count = 0;

class Employee;

class ProxyEmployee {


ProxyEmployee(c onst char *, const char *);

~ProxyEmployee( );

const char *getFirstName() const;
const char *getLastName() const;

static int getCount();


Employee *ptr;
employeeproxy.c pp

#include "employeeproxy. h"
#include "employee.h "

ProxyEmployee:: ProxyEmployee(c onst char * name, const char * surname)

ptr = new Employee(name, surname);

const char * ProxyEmployee:: getFirstName() const {
return ptr->getFirstName() ;

const char * ProxyEmployee:: getLastName() const {
return ptr->getLastName( );

int ProxyEmployee:: getCount() {
return Employee::getCo unt();

ProxyEmployee:: ~ProxyEmployee( )
delete ptr;

// Driver to test class ProxyEmployee.
#include <iostream>

using std::cout;
using std::endl;

#include <new> // C++ standard new operator

#include "employeeproxy. h" // Employee class definition

int main()
cout << "Number of employees before instantiation is "
<< ProxyEmployee:: getCount() << endl; // use class name

ProxyEmployee *e1Ptr = new Employee( "Susan", "Baker" );
ProxyEmployee *e2Ptr = new Employee( "Robert", "Jones" );

cout << "Number of employees after instantiation is "
<< e1Ptr->getCount();

cout << "\n\nEmploy ee 1: "
<< e1Ptr->getFirstName ()
<< " " << e1Ptr->getLastName( )
<< "\nEmployee 2: "
<< e2Ptr->getFirstName ()
<< " " << e2Ptr->getLastName( ) << "\n\n";

delete e1Ptr; // recapture memory
e1Ptr = 0; // disconnect pointer from free-store space
delete e2Ptr; // recapture memory
e2Ptr = 0; // disconnect pointer from free-store space

cout << "Number of employees after deletion is "
<< ProxyEmployee:: getCount() << endl;

} // end main

Jul 23 '05 #1
2 3793
What is the problem you have to start with (besides declaring using
namespacde std in a header file)?
My best guess would be a problem at the lines:
ProxyEmployee *e1Ptr = new Employee( "Susan", "Baker" );
ProxyEmployee *e2Ptr = new Employee( "Robert", "Jones" );

I expect you get a complaint that the compiler (or the linker) doesn't
know what type of object Employee is.
And a complaint that you cannot stick a pointer to an object of the
type Employee in a pointer of the type ProxyEmployee.
Try altering the lines into
ProxyEmployee *e1Ptr = new ProxyEmployee( "Susan", "Baker" );
ProxyEmployee *e2Ptr = new ProxyEmployee( "Robert", "Jones" );

Jul 23 '05 #2
ve********@hotm ail.com:

: I expect you get a complaint that the compiler (or the linker)
: know what type of object Employee is.
: And a complaint that you cannot stick a pointer to an object of the
: type Employee in a pointer of the type ProxyEmployee.

Arrrgh thanks, I'd forgotten to change those constructors!!


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Me | last post by:
Hi, I would like learn from people with experience in C++, which of the following styles of way to construct "get/set" member functions would be the best in terms of usability, speed, et cetera. The following class with be used as an example: class MyClass { public: // member function would go here. private: int data_;
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more complex operator, I get stuck. Here's a brief description what I want to do. I want to simulate a matrix (2D array) from a 1D array. so what I have so far is something like this: class Matrix
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
by: Benne Smith | last post by:
Hi, I have three enviroments; a development, a testing and a production enviroment. I'm making a big application (.exe), which uses alot of different webservices. I don't use the webservices by adding a WebReference, since it does not allow me to keep state (cookiecontainer) or to specify functions on the classes (like if i want to override the ToString() function on a class from my webservice). So the only way i can see how i can get...
by: Douglas Robson | last post by:
Ok, I've removed the MyItem class which is found in References.cs and replaced it with a reference to the namespace that has MyItem in it. I've also got rid of the tag at the top of the MyItem class. the web service works now, only the problem is, it only returns objects which are created by the default constructor. public MyItem getMyItem() {
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
by: archana | last post by:
Hi all, I want to send webrquest throguh anonymous proxy. Can anyone tell me how to validate ip address and port number of anonynmous proxy server. Is it using TctpClient class ? And while sending request through anonymous proxy if ip address of that
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
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: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.