[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I initilize a "vector <wstring> vtws" variable?

Posted on 2007-12-04
7
Medium Priority
?
884 Views
Last Modified: 2012-08-13
Hi, I'm getting a "Uninitilize memory error" in a tool called Purify.  It's pointing to my varilable declared as below. How do I initilize such variable (a vector for storing wstring)?  Thank kyou.
vector <wstring> vtws
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 20407073
There is no real need to initialize a vector, since it is a container that is filled later. If you want to, you could use

vector <wstring> vtws;

vtws.reserve(5);
0
 
LVL 86

Expert Comment

by:jkr
ID: 20407089
BTW, Is that the complete snippet? If so, Purify is wrong here.
0
 

Author Comment

by:lapucca
ID: 20407256
I think that error went away.  Let me verify and get back to you.  Thank you.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 1000 total points
ID: 20409820
Below is the correct way to initialize it; however, since vector's have a default constructor it isn't necessary and as such Purify is being less than clever about this (I have had nothing by poor experiences using Purify!).


std::vector<std::wstring> vtws = std::vector<std::wstring>();

Open in new window

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20410592
>>>> (I have had nothing by poor experiences using Purify!)
I didn't use Rational Purify myself, but all meanings I heard from were similar to the above.

>>>> vector <wstring> vtws;
Nevertheless, Purify may have detected some kind of data corruption, or show some wrong variables due to 'Precompiled Header' mix-up. If the error vanished without being reproducable, I would assume an error like that rather than a fundemental Purify problem.

Regards, Alex
0
 

Author Comment

by:lapucca
ID: 20411455
Can't use the following in the declaration in the .h file.  Got 4 errors duing compilation.
std::vector<std::wstring> vtws = std::vector<std::wstring>();
 
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20411529
Well yes, that would make sense :) You shouldn't defining things in your header file, this is what .cpp files are for. .hpp files are for declarations.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question