473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strange vector problem

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);
}
Jul 22 '05 #1
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*)
Jul 22 '05 #2
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
Jul 22 '05 #3
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

Jul 22 '05 #4
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."

Jul 22 '05 #5
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
Jul 22 '05 #6
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."

Jul 22 '05 #7
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

Jul 22 '05 #8
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.
Jul 22 '05 #9

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

Similar topics

0
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 *
3
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 =...
5
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...
7
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...
7
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; };
2
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),...
2
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 "-"...
3
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...
1
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

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.