Greetings!
Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
l_test is a pointer-to-packer that I want to check here.
The file name thing should be plain enough, whereas l_buf is declared as a
char * and contains a pointer to a data buffer.
Compress() itself has the following declaration:
Compressor_Base : public Base
{
..
..
..
public:
void Compress(const char *p_name, void *p_buf);
}
p_name takes the name of a file that is to contain the (compressed) data, and
p_buf is a pointer-to-buffer, whose contents are to be compressed (the buffer
can contain any data type, and is of no relevance for the function).
l_test is declared as type Compressor_Base and should therefore correctly
reference the function Compress().
But when compiling the source I get the following error:
main.cpp:609: error: no matching function for call to `Compressor_Nul l::
Compress(const char (*)[31], char*&)'
compressor_base .h:88: error: candidates are: void
Compressor_Base ::Compress(cons t char*, void*)
So, what's going on here?
I don't remember having included a *reference* to l_buf, and even prepending
(void *) to l_buf won't help.
Did I miss some peculiarities of void pointers, or is this some sort of bug?
Switching p_buf from void * to, for example, char * doesn't help, either - the
same type of error appears every time I attempt a compilation.
Any help would be appreciated.
--
Olaf Martens Linux User #246244 http://counter.li.org/
Hugo-Luther-Str. 8 E-Mail: ol*********@arc or.de
38118 Braunschweig Fon: +49-531-314834
"Who the heck is General Failure, and why is he reading my harddisk?" 8 1590
"Olaf Martens" <ol*********@ar cor.de> wrote in message
news:40******** *************** @newsread4.arco r-online.net... Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
What's the "&" for? l_test is a pointer-to-packer that I want to check here. The file name thing should be plain enough, whereas l_buf is declared as a char * and contains a pointer to a data buffer. Compress() itself has the following declaration:
Compressor_Base : public Base { . . . public: void Compress(const char *p_name, void *p_buf); } p_name takes the name of a file that is to contain the (compressed) data,
and p_buf is a pointer-to-buffer, whose contents are to be compressed (the
buffer can contain any data type, and is of no relevance for the function).
l_test is declared as type Compressor_Base and should therefore correctly reference the function Compress().
But when compiling the source I get the following error: main.cpp:609: error: no matching function for call to `Compressor_Nul l:: Compress(const char (*)[31], char*&)' compressor_base .h:88: error: candidates are: void Compressor_Base ::Compress(cons t char*, void*)
So, what's going on here?
Drop the ampersand.
I don't remember having included a *reference* to l_buf, and even
prepending (void *) to l_buf won't help. Did I miss some peculiarities of void pointers, or is this some sort of
bug?
No, you missed the fact that you're not supposed to take addresses
of literals.
Switching p_buf from void * to, for example, char * doesn't help, either -
the same type of error appears every time I attempt a compilation.
V
Olaf Martens wrote: Greetings!
Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
The first argument is of type const char (*)[13] (i.e. poiner to
constant array of 13 chars) here. I guess you actually meant:
l_test->Compress("file name.dat",l_buf );
where the argument is of type const char[13], which will be implicitly
converted to a pointer to its first element, i.e. a const char*.
l_test is a pointer-to-packer that I want to check here. The file name thing should be plain enough, whereas l_buf is declared as a char * and contains a pointer to a data buffer. Compress() itself has the following declaration:
Compressor_Base : public Base { . . . public: void Compress(const char *p_name, void *p_buf); } p_name takes the name of a file that is to contain the (compressed) data, and p_buf is a pointer-to-buffer, whose contents are to be compressed (the buffer can contain any data type, and is of no relevance for the function).
l_test is declared as type Compressor_Base and should therefore correctly reference the function Compress().
But when compiling the source I get the following error: main.cpp:609: error: no matching function for call to `Compressor_Nul l:: Compress(const char (*)[31], char*&)' compressor_base .h:88: error: candidates are: void Compressor_Base ::Compress(cons t char*, void*)
So, what's going on here? I don't remember having included a *reference* to l_buf, and even prepending (void *) to l_buf won't help.
The problem is not the second argument, but the first one. You are
providing a pointer to an array of char with 31 elements, while the
function wants a pointer to char.
Did I miss some peculiarities of void pointers, or is this some sort of bug? Switching p_buf from void * to, for example, char * doesn't help, either - the same type of error appears every time I attempt a compilation.
Any help would be appreciated.
--
Tell a man that there are 400 billion stars and he'll believe you.
Tell him a bench has wet paint and he has to touch it.
Victor Bazarov schrieb: "Olaf Martens" <ol*********@ar cor.de> wrote in message news:40******** *************** @newsread4.arco r-online.net...
Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
What's the "&" for?
g++ would complain otherwise and issue a warning: Deprecated conversion of
string constants to char *...
[snip] Drop the ampersand.
It's the second parameter that bothers me, not the first!
[snip] No, you missed the fact that you're not supposed to take addresses of literals.
Oh, really? And why does g++ complain when omitting the &, then?
So, once more: The problem is *NOT* the string literal, but the second
parameter (l_buf)!!!
--
Olaf Martens Linux User #246244 http://counter.li.org/
Hugo-Luther-Str. 8 E-Mail: ol*********@arc or.de
38118 Braunschweig Fon: +49-531-314834
"Who the heck is General Failure, and why is he reading my harddisk?"
Olaf Martens wrote: Victor Bazarov schrieb: "Olaf Martens" <ol*********@ar cor.de> wrote in message news:40******** *************** @newsread4.arco r-online.net...
Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
What's the "&" for? g++ would complain otherwise and issue a warning: Deprecated conversion of string constants to char *...
That doesn't make sense if your function really takes a const char* as
first parameter. That warning should only occur if the first parameter
is a pointer to non-const char.
[snip]
Drop the ampersand. It's the second parameter that bothers me, not the first!
Why?
[snip]
No, you missed the fact that you're not supposed to take addresses of literals. Oh, really? And why does g++ complain when omitting the &, then?
That hasn't anything to do with it. It complains because a string
literal cannot be modified and therefore is of type array of const
char. And for that reason, you are not supposed to convert it to a
pointer to non-const char.
So, once more: The problem is *NOT* the string literal, but the second parameter (l_buf)!!!
What makes you believe that?
"Olaf Martens" <ol*********@ar cor.de> wrote in message
news:40******** *************** @newsread2.arco r-online.net... Victor Bazarov schrieb: "Olaf Martens" <ol*********@ar cor.de> wrote in message news:40******** *************** @newsread4.arco r-online.net...
Here's another problem that appeared recently:
I have the following function call:
l_test->Compress(&"fil ename.dat",l_bu f);
What's the "&" for? g++ would complain otherwise and issue a warning: Deprecated conversion of string constants to char *...
[snip]
Drop the ampersand.
It's the second parameter that bothers me, not the first!
[snip]
No, you missed the fact that you're not supposed to take addresses of literals.
Oh, really? And why does g++ complain when omitting the &, then? So, once more: The problem is *NOT* the string literal, but the second parameter (l_buf)!!!
Look at you error message, its the first parameter that is wrong.
See the bit that says const char (*)[31], that's what &"filename.d at" is
(apart from the length which is wrong). It does not match const char*.
Remove the &, and ignore the spurious and erroneous warning.
And try to believe knowledgeable people when they give you advice. If you
don't believe this, try removing the second parameter ENTIRELY (both from
the call and the function), and you will still get the same error message.
John
On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> was alleged to have written: Remove the &, and ignore the spurious and erroneous warning.
No, fix the cause of the perfectly legitimate warning.
If the function is going to modify the argument, it is a mistake to pass
it a quoted literal.
If it is not going to modify the argument, the argument should be const
which will get rid of the warning.
"David Harmon" <so****@netcom. com> wrote in message
news:40******** *******@news.we st.earthlink.ne t... On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison" <jo************ *@hotmail.com> was alleged to have written:Remove the &, and ignore the spurious and erroneous warning.
No, fix the cause of the perfectly legitimate warning.
If the function is going to modify the argument, it is a mistake to pass it a quoted literal.
If it is not going to modify the argument, the argument should be const which will get rid of the warning.
In his quoted code the argument is const char*, therefore either he's
wrongly quoting his code or the compiler is wrong.
I do seem to recall one particular version of gcc getting this wrong, but I
might be imagining that.
John
On Sun, 1 Feb 2004 22:25:49 -0000 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> was alleged to have written: "David Harmon" <so****@netcom. com> wrote in message news:40******* ********@news.w est.earthlink.n et... On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison" <jo************ *@hotmail.com> was alleged to have written: >Remove the &, and ignore the spurious and erroneous warning.
No, fix the cause of the perfectly legitimate warning.
In his quoted code the argument is const char*,
Oh well then, the warning is bogus. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeff |
last post by:
/* --------------------------------------------------------------------------
Hello,
I was experimenting with class templates and specializing member
functions and came across a simple problem which I can't figure out.
I have a simple class C with 2 template member objects, and a function
print() that prints the value of these objects. I defined a
specialization of print() for C<string, char> which is called
correctly. Then I wanted...
|
by: troloo |
last post by:
Hello, I hope you can help me :)) The story goes as follows:
I have a class with different methods and member variables. I store
pointers to objects of this class inside a vector. Now, I would like to
have a variable 'window' which could contain pointers to different
objects (like 'class t1', 'class t2', etc.).
I tried to use templates to create variable 'T* window' but I had some
troubles later storing pointer to such a template-enabled...
|
by: sathya_me |
last post by:
Dear clc,
I have a variable void *a; Since variable "a" can be assigned (point
to) any type and also
any type can be assigned to "a" (i.e means "a" = any typed variable;
any typed variable = "a".
Considering the above I have a function, which is declared and defined
to take any type
of parameter with void*
return-type foo (void *a);
In the processes of assignment of value to the variable "a" I want to
|
by: Shawn |
last post by:
As if it won't be clear enough from my code, I'm pretty new to C
programming. This code is being compiled with an ANSI-C compatible
compiler for a microcontroller. That part, I believe, will be
irrelavent. My syntax is surely where I am going wrong.
I'd like to be able to call this routine to read different values from
another device. This routine would be called quite simply as follows:
void main()
{
|
by: thierrydollar |
last post by:
Hi,
I have written a very simple program using variable arguments calls and
I
get strange things that I cannot explain.
I have one function (add) that displays two parameters. It works well
when I call it directly.
Now I have a second function (set) that also calls add. But this
doesn't
| |
by: sonic |
last post by:
I am having trouble passing two variable types into my printPattern function. I need to pass rows and characterSelect from my getInput function into my printPattern function. I keep getting a "printPattern function does not take 0 arguments" error. I'm pretty sure this means nothing is being passed to my printPattern function, but I can't figure out why. Does anyone have any suggestions? Here's my code:
// 11/26/06
// Program allows...
|
by: Santosh Krisnan |
last post by:
hello all,
I fiddled with BASIC in the early 90s but left it at
that. Now I am trying to learn C. I tried to solve an
exercise in my book, but it failes to compile. Can
anyone tell me what the error messages mean & what I
should do?
thanks.
|
by: CptDondo |
last post by:
How do you declare a function with 0 or mroe arguments?
I have a bunch of functions like this:
void tc_cm(int row, int col);
void tc_do(void);
void tc_DO(int ln);
and I am trying to declare a pointer to them:
|
by: ares.lagae |
last post by:
- I have a typelist and I want to declare a member variable for each
of the types. How can I do that?
E.g. I have the typelist "typedef boost::mpl::vector<int, float>
types;" and I want to declare member variables with type "int" and
"float".
- I have a typelist and I want to declare a variable based on each of
the types types. How can I do that?
E.g. I have the typelist "typedef boost::mpl::vector<int, float>
types;" and I want 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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |