473,327 Members | 2,081 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,327 software developers and data experts.

Vector error in Visual

I just recently obtained a copy of Visual C++ in order to make it
easier for a friend and I to colaborate on a game. Previously, I had
been using Dev-C++.

The problem I have is that the compiler fails to recognize the vector
class. I #include <vector>, but it still has problems recognizing the
type. I have heard that including *.h files can really screw up the
compiler in this way, and I am using <stdlib.h> and <stdio.h>. I also
found out that the vector class needs the 'using std::vector'
declaration (even though string seems to work fine), but when I add
this to the code, it has problems with the following function, calling
object an undeclared identifier:

template<class C>
void INV_ReleaseContainer(C& object)
{
C temp;
temp.swap(object);
}

My friend, an experienced user of Visual C++, has no idea what is
going on, and the code compiled just fine in Dev. I have the feeling
that several things are working against me at once, so I'm not really
sure what to try next. Any help would be greatly appreciated!
Thanks!

Graeme
Jul 19 '05 #1
2 4116
Graeme wrote:
I just recently obtained a copy of Visual C++ in order to make it
easier for a friend and I to colaborate on a game. Previously, I had
been using Dev-C++.

The problem I have is that the compiler fails to recognize the vector
class. I #include <vector>, but it still has problems recognizing the
type. I have heard that including *.h files can really screw up the
compiler in this way, and I am using <stdlib.h> and <stdio.h>. I also
found out that the vector class needs the 'using std::vector'
declaration (even though string seems to work fine), but when I add
this to the code, it has problems with the following function, calling
object an undeclared identifier:

template<class C>
void INV_ReleaseContainer(C& object)
{
C temp;
temp.swap(object);
}


I assume that you are using here a vector as template argument???

Please (as usual) post the shortest possible compilable code which still has
the error. Then we will have a chance to see what is going on.

--
WW aka Attila
Jul 19 '05 #2
"Graeme" <mt*******@aol.com> wrote in message
news:1c*************************@posting.google.co m...
I just recently obtained a copy of Visual C++ in order to make it
easier for a friend and I to colaborate on a game. Previously, I had
been using Dev-C++.

The problem I have is that the compiler fails to recognize the vector
class. I #include <vector>, but it still has problems recognizing the
type. I have heard that including *.h
None of the standard C++ headers have '.h' in
their names. For #including files such as your
own headers, the file name is irrelevant, and
need only comply with naming rules of your
OS and/or implementation.

files can really screw up the
compiler
I've never seen an #include directive 'screw up' a compiler.
in this way,
In what way?
and I am using <stdlib.h> and <stdio.h>.
Those are valid (but deprecated) standard headers.
Note: beware mixing the C stdio and C++ iostream
operations, which can give unexpected results.
I also
found out that the vector class needs the 'using std::vector'
declaration
Yes, all standard C++ library identifiers (except
those of macros) are declared in namespace 'std'.
(even though string seems to work fine),
Blind acceptance of "it seems to work" is imo probably
one of the most prolific generators of inexplicable or
abberant behavior of software. Especially inconsistent
behavior. Learn the language well, and then you'll *know*
if your code is correct or not. If you *know* your code is
correct, and how it's supposed to behave, then when it doesn't,
you have excuse to point your finger at the compiler.
Otherwise not.
but when I add
this to the code, it has problems with the following function, calling
object an undeclared identifier:

template<class C>
void INV_ReleaseContainer(C& object)
{
C temp;
temp.swap(object);
}
The function looks OK to me. It should compile just
fine in a file by itself with no embellishment or change.
We'll need more context. Try to create a small, compilable
program that gives the same error and post it here.
My friend, an experienced user of Visual C++, has no idea what is
going on, and the code compiled just fine in Dev. I have the feeling
that several things are working against me at once, so I'm not really
sure what to try next. Any help would be greatly appreciated!
Thanks!


The following is adapted from your code and description,
compiles successfully with MSVC++ v6.0 (SP5), and gives
expected output:

#include <iostream>
#include <vector>
template<class C>

void INV_ReleaseContainer(C& object)
{
C temp;
temp.swap(object);
}

int main()
{
std::vector<int> vec;
for(int i = 0; i < 5; ++i)
vec.push_back(i);

std::cout << "vector contains " << vec.size() << " elements.\n";
INV_ReleaseContainer(vec);
std::cout << "vector contains " << vec.size() << " elements.\n";

return 0;
}
Output:

vector contains 5 elements.
vector contains 0 elements.
HTH,
-Mike
Jul 19 '05 #3

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

Similar topics

1
by: Alan Benn | last post by:
(VC6) When I use the STL <vector> template as follows: #include <vector> .... vector<CString> m_nameList; // Names of the chips I get these compiler warnings : C:\Program...
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
7
by: Gil | last post by:
trying to use a template in a vector, in Visual Studio 6 on Windows 2000 #include <vector> using namespace std; template <typename T> class AnyValue { T val;
11
by: sw | last post by:
Hi, Is it possible to insert a class <vec> which has a vector<double> member, into the vector<vec> veclist for e.g? I've been getting compilation errors when trying to insert using the vector...
12
by: ypjofficial | last post by:
Hello all, I have encountered with following strange problem. I am coding in C++ and using VC++ 6 compiler. I have a class strvector containing char * cstr as a private member and i have...
0
by: A Taylor | last post by:
Hello, I am getting the following error using .NET 2003 and I wonder if anyone can help me understand what is going on. godcDoc.cpp(228) : warning C4267: '=' : conversion from 'size_t' to...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
6
by: Andy | last post by:
Hi all, I started developing a little app on my Mac using XCode some month ago. The app is running fine on my mac like a sharm. Now I am nearly ready and yesterday I moved the whole source code...
3
by: vrsathyan | last post by:
Hi.., While executing the following code in purifier.., std::vector<int> vecX; vecX.clear(); int iCount = 0; { int iVal;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.