w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why is conversion from const pointer-to-const to const pointer-to-nonconst in an initializer list allowed
If constructors were const, they couldn't construct their object - they couldn't write into its data! The code you cite as "legal:" cheater.getCheaterPtr().value = 4; //oops, legal is not actually legal. While it compiles, its behaviour is undefined, because it modifies a const object through a non-const lvalue. It's exactly the same as this: const int value = 0; const int * p = &value; *const_cast<int*>(p) = 4; This will also compile, but it's still illegal (has UB).

Categories : C++

invalid conversion from 'std::string (*)(std::ofstream&, const string&, std::string, int
typedef std::string (*f_write)( std::ofstream& fout, const std::string& level_file, std::string& what_to_write, int line_num); std::string write_file( std::ofstream& fout, const std::string& level_file, std::string what_to_write, int line_num); Can you spot a difference? (Hint: compare the types of the third parameters).

Categories : C++

Can't assign string to pointer inside struct
If you want to assign a string user strcpy instead. Change your line *clinic[i].doctorname = "fernando"; to strcpy(clinic[i].doctorname, "fernando");

Categories : C

Visual Studio C++ not recognizing literal string argument as const string reference
You are trying to do SomeClass sc; // calls sc default constructor sc = "sstr"; // calls SomeClass::operator= Instead try this SomeClass sc("sstr"); // calls SomeClass::SomeClass(const string & input)

Categories : C++

C++ const std::string assignment error if the right handside contains concatenation on string literals
There is no operator + defined that takes two pointers of type const char* and returns a new array of characters containing the concatenation of the strings they point to. What you can do is: std::string message = std::string("Hello") + "world"; Or even: std::string message = "Hello" + std::string("world");

Categories : C++

Why can't I make in-class initialized `const const std::string` a static member
Your question sort of has two parts. What does the standard say? And why is it so? For a static member of type const std::string, it is required to be defined outside the class specifier and have one definition in one of the translation units. This is part of the One Definition Rule, and is specified in clause 3 of the C++ standard. But why? The problem is that an object with static storage duration needs unique static storage in the final program image, so it needs to be linked from one particular translation unit. The class specifier doesn't have a home in one translation unit, it just defines the type (which is required to be identically defined in all translation units where it is used). The reason a constant integral doesn't need storage, is that it is used by the compiler as

Categories : C++

"std::string const" versus "const std::string"
taken from: http://www.cprogramming.com/tutorial/const_correctness.html When declaring a const variable, it is possible to put const either before or after the type int const x = 5; and const int x = 4; result in x's being a constant integer. the code sample you provided is not the cause for the "strange behavior" you encountered.

Categories : C++

Convert const std::vector to const char **
It can't be done without an extra array. A const char** means "a pointer to a pointer to const char" - so you need a place where there are actual pointers to char to point to. So you need to create that array. struct c_str { const char* operator ()(const std::string& s) { return s.c_str(); } }; std::vector<const char*> pointers(args.size()); std::transform(args.begin(), args.end(), pointers.begin(), c_str()); // If you really want to be compatible with argv: pointers.push_back(0); // &pointers[0] is what you want now

Categories : C++

Compiler warning on seemingly compatible function pointer assignment (const vs no-const)
const char * is not the same as char *. From the C-standard 6.7.5.3 (emphasis by me): 15 For two function types to be compatible, both shall specify compatible return types. Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types. [...] From the C-standard 6.7.5.1 (emphasis by me): 2 For two pointer types to be compatible, both shall be identically qualified and both shall be pointers to compatible types. Note: const is a qualifier

Categories : C

- The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (String, String, String, String, String,
PreparedStatement.setString() is not a variable arity method; it doesn't take variable no. of arguments. Each placeholder(?) must be set individualy using stmt.setString(1, "Charlie Sheen"); stmt.setString(2, "help@glomindz.com"); and so on. Using Spring's JdbcTemplate jdbcTemplate.update("INSERT INTO spl_user_master(name,email,mobile,password,role,status,last_update)VALUES(?,?,?,?,?,?,?)", new Object[] { "Charlie Sheen","help@glomindz.com","9654087107","cbf51a71a11d7ec348b0d7e9b2f0055f","admin","3","null"});

Categories : Java

"std::string" or "const std::string&" argument? (the argument is internally copied and modified)
Either version clearly shows there is no intent to modify the value that is passed in. getCopy2 is more efficient in the case where an rvalue is being passed as the parameter. In that case, no copy needs to be done, since the parameter will be moved instead of copied, and you are doing no internal copying. For getCopy1, you always force at least one copy to be made. If an lvalue is being passed as the parameter, then a move needs to be done instead of creating a reference. Which is more efficient depends on a lot of details of the compiler and the string implementation, but the speed of the move should be comparable to the speed of creating a reference. I don't see any difference as far as the return value.

Categories : C++

How to copy the string referenced by a pointer into another string?
Just do: string str = msg->data; This will call the std::string copy constructor with the msg->data string as argument. The result is that msg->data is safely copied into str. Whether the actual contents are copied right away, or if it's copy-on-write is up to the implementation. You don't need to worry about that, it will "just work".

Categories : C++

Assigning const int to a const pointer to int is illegal?
If you really meant one of const int * const ptr = &size; const int * ptr = &size; that is legal. Yours is illegal. Because it it wasn't you could do int * ptr const = &size; *ptr = 42; and bah, your const was just changed. Let's see the other way around: int i = 1234; // mutable const int * ptr = &i; // allowed: forming more const-qualified pointer *i = 42; // will not compile We can't do harm on this path.

Categories : C++

How to put const string value in map
Since operator[] returns a reference (to a const std::string) you will need to use the insert() method instead. #include <map> #include <string> using namespace std; int main() { std::map<int, const std::string> m; m.insert(std::make_pair(1, "Hello")); return 0; }

Categories : C++

XML string to be stored as string in variable without parsing by PHP (xml inside JSON)
Once $v is printed, the browser just interprets the tags. If you don't want things like <span> to be treated as actual HTML, you have to escape the string. The easiest way in PHP is with htmlspecialchars(): <?php $v='<?xml version="1.0" ?><span style="font-size:10px">{point.key}</span><table>'; print htmlspecialchars($v); ?> This will escape all the greater-thans and lesser-thans, etc. and output: &lt;?xml version=&quot;1.0&quot; ?&gt;&lt;span style=&quot;font-size:10px&quot;&gt;{point.key}&lt;/span&gt;&lt;table&gt; which should give you what you want in the browser.

Categories : Xml

Difference between extern const inside namespace and static const class member?
Are there any other differences? Yes, there are. I can see two: Using the class solution you can control accessibility (public/protected/private) which is not possible with the namespace solution. Using namespace you can split the declarations across several files while this is not possible with the class solution since the class definition (which contains the declarations of all members) must be given in a single file.

Categories : C++

Android - string.equals(null) returns null pointer even when string was initialized
If your timeOut variable is null, this test will always cause a NPE, because null instances have no methods. You should be testing with == operator, e.g. timeOut == null. Why it is null, however, I can't understand, since you say it has value when printed.

Categories : Android

C# class instantiation const string
If you strings are static properties of your class they will be allocated if not they will no be allocated until they are instanciated String interning is a proccess thast is used improve memory and heap usage and allow for more efficient string comparison http://en.wikipedia.org/wiki/String_interning http://broadcast.oreilly.com/2010/08/understanding-c-stringintern-m.html

Categories : C#

Derive string from const enum
Enums are constant expressions like #define. Enums at compile time will be "translated" into the code as constants (while #define will be evaluated before compilation). So basically it is not possible to reference the enum string in this way. As suggested by others you can use a string array.

Categories : Objective C

Returning a const string from a function in C
I ran it in debug just to see what happens, somehow manner changed from "Hello" to "World" That's precisely what your code told it to do, so there's no surprise that it did what you asked for. and also the pointer changed even due I have declared it a const. You declared it a pointer to const, not a const pointer (I know, this may sound confusing). When you write const char *, it means that what's pointed to is const. If you want to say that the pointer itself is const, you need char * const manner = "Hello";

Categories : C

MultiLine string inside String.Format()?
You can do: Dim multi As String = <![CDATA[ Some multiline text ]]>.Value Now you can do: Console.WriteLine(String.Format("multi{0} string = {1}", "line", multi))

Categories : Dotnet

Why can't I return NULL from a const String& method?
NULL is not an object of type const String, so of course you can't return it when a reference to const String is expected. In fact, one of the major advantages of references is that they can't (ever) be NULL. Re-define the function to return const String *, or return an empty String.

Categories : C++

How to copy local std::string to const char *?
EDIT: note, that it answers the question as it was stated. At time of this edit it seem obvious the question is misstated wrt original intent, but improved answer can't be provided until consolidation, if it's possible at all.) Just don't do it. The whole point of using string class is to not use malloc and whatever crap. If you can't provide a const char* to a suitably stable existing location, return std::string from the function (or some other string class matching your taste).

Categories : C++

error C2664 cannot convert parameter 1 from 'std::string (__thiscall ClassName::* )(std::string)' to 'std::string (__cdecl *)(std::string)
In your real use-case can you simply make FunctionToBePointed a static method? static std::string Class1::FunctionToBePointed(std::string msg) { return msg; } If yes your code should work. The reason is that instance methods are implicitly called with an hidden this pointer, this is the thiscall calling convention, whereas static methods simply use the cdecl convention because they don't work on any instance. EDIT: A sample with Boost::bind: The MyClass C# class: using System; using System.ComponentModel; public class MyClass : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = delegate{}; private string name; public string Name { get { return name; } set { if (name

Categories : Visual C++

How can you define const static std::string in header file?
You can only initialize a static const value in the constructor for integer types, not other types. Put the declaration in the header: const static std::string foo; And put the definition in a .cpp file. const std::string classname::foo = "bar"; If the initialization is in the header file then each file that includes header file will have a definition of the static member. There will be linker errors as the code to initialize the variable will be defined in multiple .cpp files.

Categories : C++

Can a pointer alternatively point to a const empty class or a non-const class?
Well, maybe it's totally off the point, but... Could you use instance of B instead of pointer to B inside A? This would solve potential nullptr dereferencing. EDIT well, if B is too big, then you can create a lightweight wrapper around it, and store instance of that wrapper inside A. The wrapper would provide you something meaningful if B is nullptr.

Categories : C++

Why can't i pass Dictionary to IEnumerable> as generic type
Because it's a ref parameter. A ref parameter means that the method can assign a new value to the field / variable passed by the caller. Had your code been legal, the method would be able to assign a List<KeyValuePair<string, string>>, which is obviously wrong. You should not use ref parameters.

Categories : C#

std::string internal buffer corruption?
s._Bx._Buf is not a pointer, it's the internal small buffer std::string uses for holding small strings. This is called the small-buffer-optimization, or SBO. s._Bx is a union of the buffer and _Ptr, a pointer to the heap buffer that is allocated if the internal buffer is too small. So for small strings, s._Bx._Ptr should be invalid; after all, its storage is being used for the small string. Anyway ... if you get an access violation, all is not well. In such cases, the most likely cause is that you accidentally messed with the std::string's memory, most likely due to some buffer overflow or use-after-free somewhere. It's not the assignment that's interesting, it's what happens before it.

Categories : Visual C++

Error: A const field of a reference type other than string can only be initialized with null
const supports very few types; if yours isn't one of them, then in the general case you should use static readonly instead: private static readonly object VirtualImageRoot = "~/Images/Departments/"; However, it is very unclear why this isn't a string in your case: private const string VirtualImageRoot = "~/Images/Departments/";

Categories : C#

C++ character encoding when converting from string to const char* for Ruby FFI interface
The value returned by c_str() is destroyed as soon as the std::string goes out of scope. If you intend to pass this value to your script you should allocate memory and copy the string into your newly allocated space. See this example: http://www.cplusplus.com/reference/string/string/c_str/ You should also ensure the ruby script will correctly release memory. I think this is what is explained there: https://github.com/ffi/ffi/wiki/Examples. Example with a struct passed to Ruby from C: https://github.com/ffi/ffi/wiki/Examples#-structs

Categories : C++

The method managedQuery(Uri, String[], String, String[], String) from the type Activity is deprecated
The managedQuery method is deprecated, meaning it should no longer be used and there is an updated method available. The replacement for this is getContentResolver().query(): cursor = activity.getContentResolver().query(imageUri, proj, null, null, null); You can normally find out why the method is deprecated, and what you should use instead, by a quick Google of the method name, or depending on how good the javadoc is it may inform you through your IDE.

Categories : Java

how do i convert Dictionary string string to array of key value pair of string and string using linq and c#
try below , you may need to change the set properties of new object accordingly ArrayOfKeyValueOfstringstringKeyValueOfstringstring[] array = valuePairs.Select(pair => new ArrayOfKeyValueOfstringstringKeyValueOfstringstring(){ Key= pair.Key, Value= pair.Value}).ToArray();

Categories : C#

Html.fromHtml within Gmail Sender .sendMail(string, string, string, string)
It has turned out that GMailSender is a custom class published by a stackoverflow user in this post. The easiest way to send HTML instead of plain text is to change the sendMail method from the link above and replace text/plain by text/html. Or you can add a parameter to the method and make it more customizable: public synchronized void sendMail(String subject, String body, String sender, String recipients, boolean isHtml) throws Exception { try{ MimeMessage message = new MimeMessage(session); String messageType = isHtml ? "text/html" : "text/plain"; DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), messageType)); message.setSender(new InternetAddress(sender)); message.setSubject(subject); mess

Categories : Android

c++ ocurrence of a std::string inside another std::string
The following code will find the count of the non-overlapping occurrences of a given string. using namespace std; static int countOccurences(const string & line, const string & symbol) { if (symbol.empty()) return 0; if (line.empty()) return 0; int resultCount = 0; for (size_t offset = line.find(symbol); offset != string::npos; offset = line.find(symbol, offset + symbol.length())) { resultCount++; } return resultCount; } int main(int argc, const char * argv[]) { cout << countOccurences("aaabbb","b") << endl; return 0; } The find function will return either an iterator to the first element of the value it matches to or return 'last' hence string::npos. This ensures no overlap with offset + symbol.length(). I did my best to translate the varia

Categories : C++

Inserting a String inside a String
If I remember correctly, you can use the String.split() function on your string. See DotNetPerls' page on Split here. You can split the string into an array, then insert the line you want into the array, then join them back together using String.Join() (thanks Monty, I don't use Visual Basic that frequently anymore, I forgot that :)). Hope this help :)

Categories : Vb.Net

python psycopg2 internal error on string formatter
I think you have to commit the first statement that creates the table, before you can run any inserts on it. Try running cn.commit() in between your two SQL statements to see if that resolves the issue. Alternatively, set autocommit=True when you create your initial connection to the database.

Categories : Python

How to save 2 string file to internal storage in listview
Try to use Custom view for List row and implement that view into List View. Here are some of the links for Custom List Example-1 Example-2

Categories : Android

.htaccess appending query string to internal redirect
I haven't tested anything but simply looking at that line... RewriteRule ^/?([a-zA-Z0-9-_]+)/?$ /index.php?loadPage=$1&mode=cms [QSA,L] there is a syntax error. The hyphen after the 9 should be escaped as technically that is a range indicator. Most of the time you see people place it at the end before the ] and so it doesn't cause an error and so most people think they don't have to escape it. You also do not need to escape the forward slashes. Also using the question mark makes the previous optional, and don't know why you want that. So it should be like this: RewriteRule ^([a-zA-Z0-9-_]+)/?$ /index.php?loadPage=$1&mode=cms [QSA,L]

Categories : PHP

Duplicate fn:analyze-string() output using xsl:analyze-string?
You can make it a bit easier by changing the syntax of the regex, using <g> </g> for grouping rather than () (it would be possible but tiresome not to do this and instead analyse the regex and determine the groups) Once you have the group structure you can generate the normal regex using () to pass to xsl:analyze-function adding extra groups so that every text run is grouped and can be retrieved later with regex-group(). Not extensively tested so there may be bugs but something like this, and it seems to work on your examples. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="data:,f" exclude-result-prefixes="xs" > <xsl:output omit-xml-declara

Categories : Regex

internal const in generic classes seems not calculated by compiler
The problem with the compiler appears to be that at the generic phase of the compilation, sizeof(_DATA_TYPE_) is not known. And so the compiler appears to use a place holder value of 0. By the time you instantiate the generic type, sizeof(_DATA_TYPE_) is replace by the true value. But it's too late. The array type bounds checking is performed at the generic phase of the compilation at which point sizeof(_DATA_TYPE_) is 0 and so the compiler gags. That this is the case can be seen by the following code: type TemplateList<_DATA_TYPE_> = class public const SizeOfDataType = sizeof(_DATA_TYPE_); MaxListSize = Maxint div (sizeof(Integer)*SizeOfDataType); end; which produces this compiler error: [dcc32 Error]: E2098 Division by zero But, if you try this variant

Categories : Delphi



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.