declaration

What does this kind of C++ class declaration mean?

我们两清 提交于 2019-12-02 08:30:37
问题 I downloaded Ogre3D source code, and found this kind of class declaration: class _OgreExport TimeIndex { ... I know "TimeIndex" is the class name, but what is the "_OgreExport" in the middle? CPP reference doesn't include this kind of class declaration form. What is this? 回答1: _OgreExport is a preprocessor directive that expands to either __declspec(dllimport) when the file is included outside its module or __declspec(dllexport) otherwise. Under Windows, you have to specify which classes

Render a variable during creation of anonymous PHP function

南笙酒味 提交于 2019-12-02 08:04:21
问题 I'm trying to get a simple sort function going using anonymous functions. One each for asc and desc sorting. Is it possible to render the $sortBy variable right away when the function is created, but still have $x and $y passed in when called later? I want to be able to dynamically pass in a key when creating these. $sortBy = 'some_key'; // descending $sort['desc'] = function($x, $y) { if($x['data'][$sortBy] == $y['data'][$sortBy]) return 0; return ($x['data'][$sortBy] > $y['data'][$sortBy])

Where is the “proper” place to initialize class variables in AS3

余生颓废 提交于 2019-12-02 06:23:08
问题 Is it "better" to initialize AS3 class variables in the class constructor? Or can I just initialize them to their default value when I declare them at the top of my class? I ask because when there's a lot of class variables, it appears inefficient to declare them in one place and then initialize them in another when I could easily do both in the same place. It one option is better than the other, why? Thanks! eg: initializing in constructor class foo { var bar:Boolean } function foo():void {

Why does one have to repeat the const specifier at definition time, if declaration as const is done somewhere else?

落爺英雄遲暮 提交于 2019-12-02 06:12:52
After solving this simple issue , I had to ask : -> In the H file in a class ex a const static member is defined, e.g. : class ex { const static int my_ex; }; -> In the CPP file the value is specified ex::my_ex = 32; And then one gets the error "conflicting declarations" (as well as "does not name a type"). I understand that the definition in the CPP file is also a declaration which does create a conflict seen from the linker BUT why only about the const specifier (and type) and not the static one ? I only have to write const int ex::my_ex = 32; to get it to compile. But not static ... Why not

Can I declare and initialize an array with the same instruction in Java?

时光怂恿深爱的人放手 提交于 2019-12-02 06:04:52
Is there a way to do the following at the same time? static final int UN = 0; // uninitialized nodes int[] arr; // ... code ... arr = new int[size]; for (int i = 0; i < 5; i++) { arr[i] = UN; } Basically, I want to declare arr once I know what its size will be and initialize it to UN without having to loop. So something like this: int[] arr = new int[size] = UN; Is this possible? Thanks. No, not with the standard libraries. If you write your own functions, though, you can easily do so in a single statement (not instruction; those are different). Mine looks like String[][] strings = Arrayu.fill

Render a variable during creation of anonymous PHP function

有些话、适合烂在心里 提交于 2019-12-02 05:17:49
I'm trying to get a simple sort function going using anonymous functions. One each for asc and desc sorting. Is it possible to render the $sortBy variable right away when the function is created, but still have $x and $y passed in when called later? I want to be able to dynamically pass in a key when creating these. $sortBy = 'some_key'; // descending $sort['desc'] = function($x, $y) { if($x['data'][$sortBy] == $y['data'][$sortBy]) return 0; return ($x['data'][$sortBy] > $y['data'][$sortBy]) ? -1 : 1; }; uasort($arrayToSort, $sort[$order]); EDIT: I'm passing this array as a param to uasort().

Vector Initialisation in C++

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:38:45
I am using Vectors in my code. The line that is causing the error is as follows : vector<Node> alt_seq ; alt_seq = vector<Node>(1000); for(int j=0; j<alt_cf.getNoOfNodes(i); j++) { Node temp_node = *alt_itr; alt_itr++; alt_seq.push_back(temp_node); } The line : alt_seq.push_back(temp_node); causes a runtime error. However if I initialise the Vector with some initial size as follows: vector<Node> alt_seq(1000) ; In this case the code works fine. However I do not want to give an initial size as the number of objects in the vector will be variable at runtime. Please help me. I am new with C++.

Declaring variables outside loop/IF structures in C

为君一笑 提交于 2019-12-02 04:23:59
I'm new to the C language, rather programming overall. I was wondering why is it that when I declare a variable to be used within an if statement OUTSIDE the structure, that the output I've received is incorrect (for this piece of code anyway). Here's my code: #include<stdio.h> void grossPay(); int main() { grossPay(); } void grossPay() { int rate = 10, hours; double tax, grosspay, netpay; printf("Enter work hours this week: "); scanf("%d", &hours); grosspay = hours * rate; if (grosspay <= 300 && grosspay > 0) { tax = 0.10; netpay = grosspay - grosspay * tax; printf("Pay for %d hours of week

C - gcc: no compiler warning with different function-declaration/implementation

浪尽此生 提交于 2019-12-02 04:08:58
I try to figure out why my c-compiler gives me no warning/error with following (simplified) code. The function-declaration have no parameters while the function-implementation have parameters: some.h: void foo(); some.c: static uint32_t count = 0; void foo(uint32_t num) { count += num; print("Count: %u"); } main.c: foo(100); foo(); Output: Count: 100 Count: 100 Compiler for target build: gcc-arm-none-eabi-4_9-2015q1-20150306-win32 Linker for target build: gcc-arm-none-eabi-4_9-2015q1-20150306-win32 Compiler-Flags: -Wall -Werror -DuECC_CURVE=uECC_secp256r1 -DMEMORY_CHECK -DDEBUG -Os -g3

Declaring a function that return a 2D array in a header file?

女生的网名这么多〃 提交于 2019-12-02 03:50:12
I am trying to declare, within my header file, a function that returns a 2D array. How can this be accomplished, given that we already know the size of the array? Below is what I'm currently doing. class Sample { public: char[x][y] getArr(); void blah(int x, int y); private: const static int x = 8; const static int y = 2; char arr[x][y]; }; chrisaycock It turns-out my original answer was totally incorrect, but I can't delete it since it's been accepted . From two separate answers below, I was able to compile this: class Sample { const static int x = 8; const static int y = 2; public: typedef