Hi, I have encountered a simple but strange problem recently, with the STL
vector.
When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match
expected parameter type 'const char (&)[9]'.
names.push_back(str);
^^^
can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9]
typedef vector<namestring> NameArray; // name structure
NameArray names; // a global array
void lookup (namestring str)
{
names.push_back(str);
} 8 1853
"Peng" <py***@delete-this.cam.ac.uk> wrote in message
news:c7**********@pegasus.csx.cam.ac.uk... Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match expected parameter type 'const char (&)[9]'. names.push_back(str); ^^^ can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9] typedef vector<namestring> NameArray; // name structure NameArray names; // a global array
void lookup (namestring str) { names.push_back(str); }
Just a thought, but try dereferencing it
That is, instead of str, do *str
(assuming str is a char*)
On Wed, 12 May 2004 03:04:38 +0100, "Peng" <py***@delete-this.cam.ac.uk>
wrote: Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match expected parameter type 'const char (&)[9]'. names.push_back(str); ^^^ can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9] typedef vector<namestring> NameArray; // name structure NameArray names; // a global array
void lookup (namestring str) { names.push_back(str); }
You can't use a native array as a value_type in an STL container, because
arrays are not copy-assignable (one of the requirements of objects that can
be stored in STL containers). I recommend storing std::string objects in
the vector instead.
-leor
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html
Thank you. I think that should be the problem.
eng
"Leor Zolman" <le**@bdsoft.com> ????
news:6q********************************@4ax.com... On Wed, 12 May 2004 03:04:38 +0100, "Peng" <py***@delete-this.cam.ac.uk> wrote:
Hi, I have encountered a simple but strange problem recently, with the
STLvector. When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match expected parameter type 'const char (&)[9]'. names.push_back(str); ^^^ can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9] typedef vector<namestring> NameArray; // name structure NameArray names; // a global array
void lookup (namestring str) { names.push_back(str); }
You can't use a native array as a value_type in an STL container, because arrays are not copy-assignable (one of the requirements of objects that
can be stored in STL containers). I recommend storing std::string objects in the vector instead. -leor
-- Leor Zolman --- BD Software --- www.bdsoft.com On-Site Training in C/C++, Java, Perl and Unix C++ users: download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html
Peng wrote: Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match expected parameter type 'const char (&)[9]'. names.push_back(str); ^^^ can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9] typedef vector<namestring> NameArray; // name structure NameArray names; // a global array
void lookup (namestring str) { names.push_back(str); }
Not so strange. What does your compiler say about this equivalent program?
#include <vector>
int main() {
std::vector<char[9]> v(1);
return 0;
}
/david
--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."
On Wed, 12 May 2004 03:04:38 +0100, "Peng" <py***@delete-this.cam.ac.uk>
wrote: Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match expected parameter type 'const char (&)[9]'. names.push_back(str); ^^^ can any one tell me why? Thanks.
Peng
PS the code
typedef char namestring [9] typedef vector<namestring> NameArray; // name structure NameArray names; // a global array
void lookup (namestring str) { names.push_back(str); }
You can't use a native array as a value_type in an STL container, because
arrays are neither copy-constructible nor assignable (two requirements of
objects that can be stored in STL containers). I recommend storing
std::string objects in the vector instead.
-leor
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html
David Rubin wrote:
[snip] Not so strange. What does your compiler say about this equivalent program?
^^^^^^^^^^
Actually, I don't think they are equivalent, but they have the same flavor. #include <vector> int main() { std::vector<char[9]> v(1); return 0; }
/david
--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."
On Wed, 12 May 2004 03:03:21 GMT, Leor Zolman <le**@bdsoft.com> wrote: You can't use a native array as a value_type in an STL container, because arrays are neither copy-constructible nor assignable (two requirements of objects that can be stored in STL containers). I recommend storing std::string objects in the vector instead. -leor
Sorry for the double-post... I've had news server problems tonight. On
top of that, a dialog box Agent put up led me to believe I had the
option of actually "replacing" a previous post with an updated
version. I thought to myself, "Gee, this is great! If I post something
with a typo, I can just update it!" and proceeded to attempt that for
this post. Clearly it doesn't do that...probably just as well. I guess
it would be pretty chaotic if anyone could dynamically correct their
posts so that responses to the original version would no longer make
sense...
-leor
David Rubin <fu******@warpmail.net> wrote in message news:<Fi*********************@twister.nyc.rr.com>. .. What does your compiler say about this ... program?
#include <vector> int main() { std::vector<char[9]> v(1); return 0; }
Invalid argument to std::vector - cannot copy char[9].
Regards,
Michiel Salters. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil |
last post by:
Hi,
I don't understand this strange behaviour:
I compile this code :
#include <Python.h>
#include"Numeric/arrayobject.h"
static PyObject *
|
by: Al Newton |
last post by:
My class has this member function:
vector<UniqueCustId*>* CMyClass::GetCustList( void )
{
SYSTEMTIME st;
string strServiceDate;
UniqueCustId* uci = new UniqueCustId;
string strCustNumberOld =...
|
by: Rob Ristroph |
last post by:
Hi,
It's pretty unhelpful to post "I have a huge piece of code that
crashes in strange places, what's the problem?" but that's basically
my problem and I really am at my wit's end.
The piece...
|
by: cppaddict |
last post by:
Hi,
I've been trying to debug a strange runtime error for the last 5
hours... I'm hoping someone might have an insight about it.
I have an application that creates a vector of MyDisplay...
|
by: Hamish |
last post by:
Hello, lately I've been having a lot of trouble with the std::vector. Seems
to create unpredictable behaviour within my code.
Example:
struct Switch{
int i;
int j;
double d;
};
|
by: Dave |
last post by:
I'm crossposting this to both comp.lang.c++ and gnu.gcc because I'm not
sure if this is correct behavior or not, and I'm using the gcc STL and
compiler.
When calling vector<int>::push_back(0),...
|
by: Leszek Taratuta |
last post by:
Hello,
I posted this problem a few days ago. I am not sure if I was not enough
specific but nobody answered, so I am posting it again:
I have the following code snippet that overloads the "-"...
|
by: Mike Durham |
last post by:
Hi all,
I have a problem with the Linux STL (I think!)
Can anyone explain why I get the error indicated below?
BTW if I use the <vector.h> (backward version) it compiles without
error. I just...
|
by: zl2k |
last post by:
hi, all
I am not sure of this question is suitable for the c++ language group
but still hope the experts here can give me some hints.
I am using gcc 3.4.4 in fc3 and got a very strang error when...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
| |