When I try to compile this I get this error:
error: expected `;' before 'it'
Why I can't declare this iterator? I don't understand...
#include <list>
template <typename Z>
class LBFuncBase: public LBBaseBlock<Z>
{
void Something() {
std::list<LBBaseBlock< Z >* >::iterator it;
}
}
...
Hello,
I would like a C++ constructor/method to be able to take any container as argument.
In C# this would be easy by using IEnumerable, is there an equivalent in C++/STL ?
Anthony
...
I need to implement an std::map with pairs. The function pointers are pointers to methods of the same class that owns the map. The idea is to have direct access to the methods instead of implementing a switch or an equivalent.
( I am using std::string as keys for the map )
I'm quite new to C++, so could anyone post some pseudo-code or...
I have a symbol table implemented as a std::map. For the value, there is no way to legitimately construct an instance of the value type via a default constructor. However if I don't provide a default constructor, I get a compiler error and if I make the constructor assert, my program compile just fine but crashes inside of map<K,V>::oper...
I've try to compile this code:
#include <iostream>
#include <cstdlib>
using namespace std;
#define ARRAY_TAM 2
typedef int (*operacion)(int, int);
typedef const char* (*Pfchar)();
int suma(int, int);
int resta(int, int);
const char* descrSuma();
const char* descrResta();
const char* simbSuma();
const char* simbResta();
class OP
{
...
I want to create a big std::vector so operator[] should receive long long rather than unsigned int, I tried writing my own allocator:
template <typename T>
struct allocator64 : std::allocator<T> {
typedef long long difference_type;
typedef unsigned long long size_type;
};
But when I try the following:
long long n = 5;
std::ve...
How is the destructor for the vector managed when adding elements to this list? Is the object destroyed correctly when it goes out of scope? Are there cases where it would not delete the object correctly? For example what are the consequences if "table" was a child of object, and we added a new table to a vector of object pointers?
vect...
What is the cleanest way of converting a std::wstring into a std::string? I have used W2A et al macros in the past, but I have never liked them.
...
Hi, I'm trying to check if value is in a map and somewhat can't do it:
typedef map<string,string>::iterator mi;
map<string, string> m;
m.insert(make_pair("f","++--"));
pair<mi,mi> p = m.equal_range("f");//I'm not sure if equal_range does what I want
cout << p.first;//I'm getting error here
so how can I print what is in...
I use std::stringstream extensively to construct strings and error messages in my application. The stringstreams are usually very short life automatic variables.
Will such usage cause heap reallocation for every variable?
Should I switch from temporary to class-member stringstream variable?
In latter case how can I reserve stringstrea...
Imagine that we have two static libraries built with different implementations of std::vector. Both of these binaries would have the code for both push_back and pop_back (since vector is usually header only). What would the linker do when we tried to use both of these libraries in a project. Would it give an error? Could the linker remo...
I'm very new to STL, and pretty new to C++ in general. I'm trying to get the equivalent of a .NET Dictionary<string, value>(StringComparer.OrdinalIgnoreCase) but in C++. This is roughly what I'm trying:
stdext::hash_map<LPCWSTR, SomeStruct> someMap;
someMap.insert(stdext::pair<LPCWSTR, SomeStruct>(L"a string", struct));
someMap.find(L...
When copying data from one range to another, you have to be careful if there's partial overlap between the source and destination ranges. If the beginning of the destination range overlaps the tail of the source range, a plain sequential copy will garble the data. The C run-time library has memmove in addition to memcopy to handle such...
In my development environment, I'm compiling a code base using GNU C++ 3.4.6. Code is under development, and unfortunately crashes now and then. It's nice to be able to run the traceback through a demangler, and I use c++filt 3.4. The problem comes when functions have a number of STL parameters. Consider
My_callback::operator()(
Stat...
Using STL, I want to find the last instance of a certain value in a sequence.
This example will find the first instance of 0 in a vector of ints.
#include <algorithm>
#include <iterator>
#include <vector>
typedef std::vector<int> intvec;
intvec values;
// ... ints are added to values
intvec::const_iterator split = std::find(values.beg...
What am I doing wrong?
#include <iostream>
#include <deque>
using namespace std;
struct mystruct {
int number1;
int number2;
};
int main() {
std::deque<mystruct> mydeque;
mydeque.number1.push_front(77);
return 0;
}
...
I know the STL has set_difference, but I need to just know if 2 sets are disjoint. I've profiled my code and this is slowing my app down quite a bit. Is there an easy way to see if 2 sets are disjoint, or do I need to just roll my own code?
EDIT: I also tried set_intersection but it took the same time...
...
i created a map.
i want to print the index of the key to a file using the itr in the map.
this is what i mean:
map <string,int> VendorList;
VendorList[abc] = 0;
VendorList[mazda] = 111;
VendorList[ford] = 222;
VendorList[zoo] = 444;
map <string,int>::iterator itr=VendorList.find("ford");
fstream textfile;
textfile << itr;
if i put i...
I want to refresh my STL knowledge before interview. Could anyone recommend good short and freely downloadable STL tutorial? Thank you.
EDIT: Preferably in PDF.
...
I understand that when we insert values into the STL map, a copy is made and stored.
I have code that essentially does a find on the map and obtains an iterator.
I then intend to use the iterator to change the value in the map.
The results are not what I would expect ie: the value is not changed when accessed from another part of the pr...