How declare return type as inner class of template typename?
How declare this: template<typename T> (T::ABC)& get(); it gives error: error: expected constructor, destructor, or type conversion before ‘&’ token ...
How declare this: template<typename T> (T::ABC)& get(); it gives error: error: expected constructor, destructor, or type conversion before ‘&’ token ...
I need comment my function prototype (written in C/C++) with summary, returns, param tags. How can I persuade Visual Studio to insert xml tags after three forward slashes like in C#? I found one solution. When I rename xx.h xx.cs in C++ project, I can use /// for generating xml comments (IntelliSense in xml comments works too). There mus...
You would think this would be readily available, but I'm having a hard time finding a simple library function that will convert a C or C++ string from ISO-8859-1 coding to UTF-8. I'm reading data that is in 8-bit ISO-8859-1 encoding, but need to convert it to a UTF-8 string for use in an SQLite database and eventually an Android app. I ...
what exactly does the 'const' keyword in c++ mean when it's written at the end of a member function (after the argument list)? thanks! ...
#ifndef ECORE_H #include "../database.h" #define ECORE_H Database *base_provider; // ecore.h: error: expected initializer before ‘*’ token template <class S, class T> class ecore { // error: expected class-name before ‘{’ token public: ~ecore(void){delete base_provider;}; ecore(vo...
template<typename T> std::istream & read(std::istream & istr, typename std::enable_if<std::is_pod<T>::value, T>::type & value) { return istr.read( reinterpret_cast<char*>(&value), sizeof(T)); } int main() { int x; read(cin, x); // error here } error C2783: 'std::istream &read(std::istream &,std::enable_if<std::tr1::is_pod...
Hello All: I have a linked list of structs each of which contains an integer and a pointer to the next struct. Before populating this struct by a sequence of new commands, I note down the memory used (say Mem_1) by this program in Windows Task Manager under "Mem Usage". The actual linked list creation occurs next. (See void populate(int...
Is it possible to have a function that returns an array of variable size? My plan is to have the size of the returned array as the first member of the array (so ret_val[0] = # of members in ret_val). The problem then becomes with initializing an array to the return value of that function. int moves[] = target_function() wouldn't pos...
Hello, How to find char in a char array by using find function? If I just for loop the vowel then I could have gotten the answer but I'm asked to use std::find.. Thanks. bool IsVowel (char c) { char vowel[] = {'a', 'e', 'i', 'o', 'u'}; bool rtn = std::find(vowel, vowel + 5, c); std::cout << " Trace : " << c...
I'm trying to compile the following program using Qt Creator 2.0.1: void f() { string a = "abc"; transform(a.begin(), a.end(), a.begin(), ptr_fun(tolower)); } mingw throws the following error: no matching function for call to ptr_fun( < unresolved overloaded function type > ) That function compiles fine with VC++ 2010 Expres...
I'm using Visual C++ 2010 Express and I just started learning C++. So when I want to run this code: #include <iostream> using namespace std; int main(){ cout << "Hello World! "; return 0; } It works, but the program exits immediately after I started it, how should I keep the program alive? ...
I have the following code, which loops through an array of menuoptions and on each iteration, creates a ScaledRect object and pushes it to a vector. This vector is a member of a struct. I have verified that the ScaledRect is created with the correct values, yet when I print back the contents of the regions vector ( in the second loop )...
Hello, It might be a stupid question but just wonder if there is any workaround. :) Is there any way to have "Not" in Predicate? Example: std::remove_if(s.begin(), s.end(), !IsCorrect); // ^ Or, Do I have to create IsNotCorrect function anyways? ...
Hi all. I'm especially interested of windows, mingw. Thanks. Update: First, I thought everyone is familiar with string interning. http://en.wikipedia.org/wiki/String_interning Second, my problem is in detail: I knocked up a string class for practice. Nothing fancy you know, i just store the size and a char * in a class. I use memcpy...
I'm wondering why the declare-before-use rule of C++ doesn't hold inside a class. Look at this example: #ifdef BASE struct Base { #endif struct B; struct A { B *b; A(){ b->foo(); } }; struct B { void foo() {} }; #ifdef BASE }; #endif int main( ) { return 0; } If BASE is defined, the code ...
Let's say I have a bunch of Donut objects, and each of these donuts has a public integer attribute diameter. If I have a vector of donuts, how can I extract the donut with the smallest or largest diameter? ...
Hi, How to make the hardware beep sound with c++? Thanks ...
I started thinking about this after receiving an answer for this question. This is a bit tricky to explain, but I'll do my best. I'm building a small(ish) 2D game engine. There are certain requirements that I need to satisfy, since this engine has to "work" with existing code that others have written for a different engine. Some change ...
I have a C++ windows service that sometimes crashes when I call the system() function to shell out a command. I've run the exact text of the command in the windows command-line, and it runs just fine, but for some reason it fails when system() is run. To make matters worse, I can't seem to get any information as to why system() is faili...
Lets say I have a function str_rev(string &s, int len) {} which reverses the string s of length len I want to reverse a substring of long string starting at index 5 and of length 10 for this I was forced to first call substring function and then call the str_rev function passing the substring sub_string = long_str.substr(5, 10) st...