473,666 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ReleaseCont ainer(C& object)
{
C temp;
temp.swap(objec t);
}

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 4143
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_ReleaseCont ainer(C& object)
{
C temp;
temp.swap(objec t);
}


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.goog le.com...
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_ReleaseCont ainer(C& object)
{
C temp;
temp.swap(objec t);
}
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_ReleaseCont ainer(C& object)
{
C temp;
temp.swap(objec t);
}

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_ReleaseCont ainer(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
5910
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 Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal parameter
7
10622
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 namespace std; : : vector<string>* getTyphoon()
7
8193
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
6302
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 method push_back() -> c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2679: binary '=' : no operator defined which takes a right-hand
12
1807
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 defined its destructor for releasing memory hold by cstr. In main i created a vector<strvector> and whenever i put a object of strvector inside this vector the program crashes.
0
1892
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 'int', possible loss of data C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(621) : error C2440: 'initializing' : cannot
6
5634
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. char temp; std::vector<unsigned charmmessage; while (!done){
6
11077
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 to a Windows PC and build it in MS VC++. Now I got a lot of "vector subscript out of range" assertion errors and I don't know why because on my Mac it is working without any error. What does the Mac with this problems and what is the magic behind...
3
2821
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
8440
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, 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...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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,...
0
8636
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 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...
0
7378
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, 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...
0
5661
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();...
0
4192
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...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.