I'm an old Delphi programmer getting into the C++ world, and trying to wrap my head around this problem.
I have multiple classes derived from a generic class that passes one of it's functions as a parameter to another function. The code is very complex, so I've written this abridged version of what I am trying to do. - // genClass.h
-
#ifndef genClassH
-
#define genClassH
-
-
#include <Classes.hpp>
-
-
// Class declerations
-
class genClass
-
{
-
virtual char *doStuff(char *) = 0;
-
char *doIt(char *,char *);
-
};
-
-
class getFive : genClass
-
{
-
char *doStuff(char *input);
-
};
-
-
class getThree : genClass
-
{
-
char *doStuff(char *input);
-
};
-
-
// Function
-
char *genFunc(char *,char *(*func)(char *));
-
-
#endif
- // genClass.cpp
-
#pragma hdrstop
-
#include "genClass.h"
-
#pragma package(smart_init)
-
-
// Class member definitions
-
char *getFive::doStuff(char *input)
-
{
-
char *result;
-
strncpy(result,input,5);
-
return result;
-
}
-
-
char *getThree::doStuff(char *input)
-
{
-
char *result;
-
strncpy(result,input,3);
-
return result;
-
}
-
-
char *genClass::doIt(char *pre,char *str)
-
{
-
return genFunc(pre,doStuff(str));
-
}
-
-
// Function definition
-
char *genFunc(char *pre,char *(*func)(char *input))
-
{
-
char *result;
-
strcpy(result,pre);
-
strcat(result,func);
-
return result;
-
}
I'm trying to compile this in Borland C++ Builder. I think I've overly confused myself, but this is where I'm stuck.
My error message is:
[C++ Error] genClass.cpp(23 ): E2034 Cannot convert 'char *' to 'char * (*)(char *)'
TIA for any help.
1 1586
Several things:
1)There are no public/private specifiers. You will probably need these.
2) This code:
char *getFive::doStu ff(char *input)
{
char *result;
strncpy(result, input,5);
return result;
}
does not allocate memory for result before copying data to that location. Guranteed program crash here. Other places have the same problem.
3) This code:
char *genClass::doIt (char *pre,char *str)
{
return genFunc(pre,doS tuff(str));
}
does a call to doStuff(str). That call returns a char*. The argument is supposed to be a function pointer. Hence, the compiler bark about not being able to convert a char* to a function pointer.
4) What are you trying to do??
The way these classes are set up and used looks very incorrect.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul |
last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and
session.use_trans_sid = 1 in my php.ini file. Index.php contains:
----------------------------------------------------------------------------
<?php
ini_set("session.use_cookies", "off");
ini_set("session.use_trans_sid", "on");
session_start();
$_SESSION = "";
$_SESSION = "";
echo "<form method='POST' action='login.php'>
|
by: Erik Haugen |
last post by:
From reading gotw#84 (http://www.gotw.ca/gotw/084.htm), I'm convinced that
I should try to make functions nonfriend nonmembers when practical, but
then I came across this:
Bruce Eckel says about operator overloads in Thinking In C++ (2nd Ed -
http://www.codeguru.com/cpp/tic/tic0129.shtml)
"In general, if it doesn't make any difference, they should be members, to
emphasize the association between the operator and its class."
That seems...
|
by: Angus Leeming |
last post by:
Dinkumware's online STL reference http://tinyurl.com/3es52 declares
std::map's overloaded erase member functions to have the interface:
map::erase
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
size_type erase(const Key& keyval);
Ie, the first two functions above have the same interface as
|
by: Resant |
last post by:
I have a query :
Exec 'Select * From Receiving Where Code In (' + @pCode + ')'
@pCode will contain more than one string parameter, eg : A1, A2, A3
How can i write that parameters, I try use :
set @pCode='A1','A2','A3'
but get an error : Incorrect syntax near ','
|
by: blue |
last post by:
We often get connection pooling errors saying that there are no available
connections in the pool.
I think the problem is that we are passing around open readers all over the
place. I am planning on changing this in our code and I expect this to fix
our problem.
We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we...
| |
by: tkrogc |
last post by:
I compiled the source below using the comeau compiler
http://www.comeaucomputing.com/tryitout/
Why does the f funtion compile while the g function produces an lvalue
error ?
(I thought the two functions were identical except for a harmless
syntax difference)
struct A
{
void f(){}
|
by: =?ISO-8859-15?Q?Sven_K=F6hler?= |
last post by:
Hi,
look at this example:
struct T1 {
bool v;
T1(bool p = false) {
this->v = p;
}
|
by: dascandy |
last post by:
Hello,
I was wondering, why is overloading operator. (period) forbidden? It
would make a few odd applications possible (dynamic inheritance and
transparent remote method invocation spring to my mind) and it would
be fairly generic. The only sidecase I can see is that operator.
itself would not be looked up through operator. .
I read that there was previous debate on the subject, but I haven't
been able to find why it was rejected.
|
by: sanjay |
last post by:
Hi,
I have a doubt about passing values to a function accepting string.
======================================
#include <iostream>
using namespace std;
int main()
{
|
by: tarunkhatri |
last post by:
Hi,
I want to pass the parameter of employee_id to a page. My code is working fine and passing parameter to page but the problem is rather then the current parameter. It passed the parameter which was selected in previous submit. Below is the code.
<form action='manager_employee_select.php?proc_employee_id=<?php echo $_POST; ?>' method="POST">
<table>
<tr> My team members timesheet</tr>
<tr>Select a team member from the list 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: 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...
| |