casting

any_cast std::any pointer to specific pointer type

≯℡__Kan透↙ 提交于 2019-12-11 06:06:16
问题 I would like std::map<string, any> *var1 to point to the same memory address/value as std::any *var2 because I know that var2 is pointing to a map<string, any> . The following seems to work: std::map<string, any> *var1 = any_cast<std::map<string, any>>(var2); Is it ok? The problem is that it does not signal bad cast even if var2 is actually not an std::map<string, any>* but something else, but if it is it still works. Am I doing it right? std::map<string, any> *mapptr; std::any realmap = std:

Can't convert character to numeric in R

假如想象 提交于 2019-12-11 06:02:03
问题 I'm trying to convert values from character to numeric, but R introduces NAs. I have examined one of the problematic values: > x [1] "11 914 711.5" > length(x) [1] 1 > typeof(x) [1] "character" > as.numeric(x) [1] NA Warning message: NAs introduced by coercion Does anybody have any idea how to fix this? 回答1: You could first split your string and then convert them to numeric: as.numeric(unlist(strsplit(x, ' '))) [1] 11.0 914.0 711.5 回答2: It's not clear what you want. The previous answers and

Java API design: narrow return type in methods

两盒软妹~` 提交于 2019-12-11 06:00:25
问题 Suppose I have a type family, I have defined a set of methods in base type: interface Foo<T> { Foo<T> a(); Foo<T> b(); ... } And Bar extends Foo interface Bar<T> extends Foo<T> { Bar<T> a(); Bar<T> b(); ... } And then Zee extends Bar interface Zee<T> extends Bar<T> { Zee<T> a(); Zee<T> b(); ... } When I implement this type family with different decorators, I found I constantly write something like class XBar<T> extends XFoo<T> implements Bar<T> { Bar<T> a() { return (Bar<T>)super.a(); } Bar<T

Cast char to a bit field entry of 4 bits

老子叫甜甜 提交于 2019-12-11 05:54:46
问题 Hello guys I'm facing another problem, I'm working on single bits and extract data from ascii text. The problem is that the compiler gives me an error about the fact that casting a char (8 bits) to a 4 bit memory field may alter its value. Obviously that's true but how could I overcome that error? typedef struct { struct { unsigned int type: 4; unsigned int uid: 8; unsigned int operation: 4; unsigned int reg: 16; }header; char *arg_nm; } OWL_request; The complete error: error: conversion to

MediaRouterProvider not visible in the network

a 夏天 提交于 2019-12-11 05:53:15
问题 I created a SampleMediaRouteProvider as given in https://github.com/googlesamples/android-MediaRouter. In this sample there is also a MediaRouter that discovers all MediaRouteProviders in the network. This SampleMediaRouteProvider is visible in the same device to other apps but its not visible to apps on other device in the same network. Can you please help me to get MediaRouteProvider visible in wifi network. Iam looking to create a MediaRenderer on a Android device that I could use to cast

Downcasting template typename object in C++

自作多情 提交于 2019-12-11 05:38:01
问题 I have the following function in a C++ application that is called many different times: template<typename The_ValueType> void handleObject(The_ValueType const &the_value) //unchangable function signature { /* //Pseudo Java code (not sure how to implement in C++) if (the_value instanceof Person){ Person person = (Person) the_value //do something with person } if (the_value instanceof Integer){ int theInt = (Integer) the_value //do something with int } */ } I need to print out some debugging

Why are bar graphs acting so strangely? html5 canvas, and javascript

我是研究僧i 提交于 2019-12-11 05:35:32
问题 For my first foray into html5, I'm trying to make a scoreboard for the game Farkle. I have figured out how to make a lame looking but functional graph system for up to five players, but I cannot figure out how to have it update more than once. I realize that my code could be much better, but I didn't want to write helper functions until I was sure how it would work. As it is now, I'm getting weird behavior from the boxes. Rather than adding the "tally" to the total score, and drawing a box to

C2440 static_cast cannot convert from base class to derived class

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 05:35:26
问题 I am attempting to understand why casting from a base class to an derived class using pointers compiles fine, but casting using non-pointer object produces the error C2440. Below I have a base class ThreadedMessage that is inherited by class GPSMessage . struct ThreadedMessage { ThreadedMessage() : m_Type(0), m_ID(0) { } ThreadedMessage(uint Type, uint ID = 0) : m_Type(Type), m_ID(ID) { } uint m_Type; uint m_ID; }; struct GPSMessage : public ThreadedMessage { GPSMessage() : ThreadedMessage()

Storing DaysOfWeek as single integer in sqlite database using enum/bitwise - Java

故事扮演 提交于 2019-12-11 05:32:01
问题 Here's what I'm trying to do. I have a field that encompasses multiple days per week. (E.g. it can store MONDAY or MONDAY | TUESDAY, or WEDNESDAY | FRIDAY) - basically any combination. To do this I used an enum with powers of 2, like this: public enum DayOfWeek { Monday(1), Tuesday(2), Wednesday(4), Thursday(8), Friday(16), Saturday(32), Sunday(64); private final int index; DayOfWeek(int index) { this.index = index; } public int value() { return index; } } Then I store an integer in the

cast base class pointer to one of several possible derived type pointer based on condition

半世苍凉 提交于 2019-12-11 05:27:48
问题 I have a base class B and several derived template classes D<int> , D<float> , D<double> , etc. (so more than ten) In my program, I find a situation where I have a B pointer that I KNOW points to an instance one of the D specializations. I also have a unique key that identifies the derived type. So, I want to call the correct derived class method using my base class pointer and the unique type key. I actually want to do this in several places, so the one solution I have come up with is not