casting

C++ object and C style cast question

a 夏天 提交于 2019-12-12 04:36:28
问题 I have the following code compiled by gcc: #include <iostream> using namespace std; class Buffer { public: operator char *() { cout << "operator const * called" << endl; return buff; } private: char buff[1024]; }; int main(int, char**) { Buffer b; (char *)b; // Buffer::operator char * is called here return 0; } What I see is that Buffer::operator char * is called on line: (char *)b; Why C style cast calls Buffer::operator char * is called here? I though that static_cast<char *>(b); should be

Reversing typeof to use Linq Field<T>

[亡魂溺海] 提交于 2019-12-12 04:35:50
问题 I want to use Linq to dynamically select DataTable columns by ColumnName but to use Field<> I must explicitly cast them or box everything to an object, which is not efficient. I tried: string[] colsNames = new[] { "Colum1", "Colum2" }; DataTable dt = StoredProcedure().Tables[0]; var cols = dt.Columns.Cast<DataColumn>().Where(c => cols.Contains(c.ColumnName)); if (cols.Any()) { dt.AsEnumerable().Select(r => string.Join(":", cols.Select(c => r.Field<c.DataType>(c.ColumnName)))) } but this

How do Fortran and MPI_Reduce deal with integer overflow?

久未见 提交于 2019-12-12 04:33:58
问题 Following this thread, I want to cast a single / double precision real number "AA" into an integer "II" to compute the checksum of a distributed variable. Following comments, I have used the intrinsic 'transfer' and rewritten completely this post. Below is a small fortran module that can be used to compute checksums of distributed arrays which depends on the library 2DECOMP&FFT. The module seems to work on my workstation (gfortran 4.9.2, openmpi 1.6.5, 4 processors). Any comment / remark that

PHP Laravel: Type of var is different from local to server

£可爱£侵袭症+ 提交于 2019-12-12 04:32:19
问题 I've encountered a strange bug in my Laravel application. A property status of a model x is an integer in localhost, but is a string in my production server. "status" => 1 "status" => "1" This throws an error in my application because I'm using strict comparison. Both use Laravel Framework 5.4.1 on PHP 5.6, with MySQL. So I have no idea where the difference comes from... Do you? 回答1: It depends on the driver used between php and mysql. Check which one of them is used by checking pdo_mysql

copy base class data from one derived class to another

那年仲夏 提交于 2019-12-12 03:55:15
问题 Suppose I have three classes: typedef struct base { float A; float B; ... base() : A(1.0f), B(1.0f) {} } base; class derived1 : base { int C; int D; }; class derived2 : base { int E; int F; }; And I would like to copy base class data from one derived class object to another. Is it safe to do the following, to only copy the base class values of A, B, etc... from one object to another? derived1* object1 = new derived1; derived2* object2 = new derived2; void make_object1() { object1->C = 2;

C - pointers when new functions are called [closed]

余生长醉 提交于 2019-12-12 03:55:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Say I have something like: function2(int *hello) { //something } function1(int *hello) { function2(&hello); } void main() { int hello = 0; function1(&hello); } How do I make it so that function2 can change the original value declared in main ? 回答1: Change this code: function1(int *hello) { function2(&hello); }

Type casting and Comparison with Loose Operator “==”

橙三吉。 提交于 2019-12-12 03:50:15
问题 I have a problem baffling me terribly. I noticed this before but didn't give it any heed until today. I was trying to write my own check for integer strings. I know of is_numeric() but it does not suffice since it counts float as numeric not only integers and is_int() which does not work on string numbers. I did something similar to this $var1 = 'string'; $var2 = '123'; var_dump( (int)$var1 == $var1);// boolean true var_dump((int)$var2 == $var2);// boolean true var_dump((int)$var1);//int 0

Parameters referenced from the same variable point to different locations

元气小坏坏 提交于 2019-12-12 03:48:44
问题 I'm trying to store HWND pointers in an int vector along with other data, I'm using the following code to get the data and store it on creation: void createscalingwindow(HWND &cswpara0,DWORD cswpara1,const CHAR* cswpara2, const CHAR* cswpara3,DWORD cswpara4,int cswpara5, int cswpara6,int cswpara7,int cswpara8,HWND cswpara9, HMENU cswpara10,HINSTANCE cswpara11,LPVOID cswpara12) { cswpara0 = CreateWindowEx (cswpara1, cswpara2, cswpara3, cswpara4, cswpara5, cswpara6,cswpara7,cswpara8,cswpara9

“Un-casting” from (void *) and de-referencing to char array

独自空忆成欢 提交于 2019-12-12 03:47:19
问题 I have almost completed an homework assignment where I am required to use pthreads. I have figured out the pthreads. The only problem I have left is figuring out how to pass multiple arguments to threads through pthread_create(). I need to pass two chars to the thread. I have to cast them to (*void) to use with pthread_create(). I can pass them, but I can't figure out how to get the values from *parameter in the function. void *my_function(void *parameter) { /* ATTEMPT 1 - DOESN'T WORK */ /

Is there a way to create an instance of a subclass from its base class? I need it for my custom wrapper of TcpClient/Listener

大憨熊 提交于 2019-12-12 03:39:19
问题 I'm writing classes which wrap around the TcpListener and TcpClient classes in VB. Currently here is my wrapper of the TcpListener class: Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class XXXTcpServer : Inherits TcpListener Public name As String Public clients As List(Of TcpClient) Public maxClients As Integer = -1 ... Sub New(Optional ByVal name As String = "", Optional ByVal port As Int32 = 30000, Optional ByVal localAddr As IPAddress = Nothing) MyBase.New(If