declaration

recurrent declare in c

Hi All, typedef void (callback)(int *p1, sStruct *p2); typedef struct _sStruct { callback *funct; }sStruct; I have the following declaration, in C. How can I compile this recurrent declaration without receiving any error ? For the moment I receive: syntax error before '*' token on first line. ...

Should I fully declare throw-away objects?

If I need to do something like this: var connection = new Connection(host); connection.Execute(Commands.Delete); Is there anything wrong in doing this: (new Connection(host)).Execute(Commands.Delete); The first example may be more readable, but the second works better if I need to do this multiple times: (new Connection(anotherHos...

Scope of class declaration

I have a file classes.php in which I declare a set of classes to be used in a series of pages. Then, in one page, I need to use another class, that is declared in a separate file. Now, this separate class uses some classes located in the classes.php file. So, in most pages, I have: [1] <?php require('classes.php'); [page code] ?> whi...

How can I simplify interface declarations in C++?

My interface declarations usually (always?) follow the same scheme. Here's an example: class Output { public: virtual ~Output() { } virtual void write( const std::vector<char> &data ) = 0; protected: Output() { } private: Output( const Output &rhs ); // intentionally not implemented void operator=( const Output &o...

C++ variable declaration and initialization rules

Consider the following ways of declaring and initializing a variable of type C: C c1; C c2; c2 = C(); C c3(C()); C c4 = C(); Are all of these completely equivalent to each other, or can some of these differ depending on the exact definition of C? (assuming it has public default and copy constructors). ...

Putting class static members definition into cpp file -- technical limitation?

Hi, one of my "favorite" annoyance when coding in C++ is declaring some static variable in my class and then looking at compilation error about unresolved static variable (in earlier times, I was always scared as hell what does it mean). I mean classic example like: Test.h class Test { private: static int m_staticVar; int m_var; ...

How do you declare a pointer to a function that returns a pointer to an array of int values in C / C++?

Is this correct? int (*(*ptr)())[]; I know this is trivial, but I was looking at an old test about these kind of constructs, and this particular combination wasn't on the test and it's really driving me crazy; I just have to make sure. Is there a clear and solid understandable rule to these kind of declarations? (ie: pointer to... arr...

How to correctly write declarations of extern arrays (and double arrays) in C's header files?

Suppose I want to share a global array of data across my program, for example: int lookup_indexes[] = { -1, 1, 1, -1, 2, 1, 1, -2, 2, 2, -1, 1, 1, 2 }; What is the correct extern declaration for this array in the C header file? Also what about an array like this: int double_indexes[][5] = { { -1, 1, 1, -1, 1 }, { 2, -2, 2, 1, -1 } }...

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

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 thi...

Declaring bool variable in c on linux platform

How to declare a variable of bool datatype in C running on Linux platform. I tried the following but its giving an error: #include<stdio.h> #include<string.h> bool factors[1000] void main() { } ...

JavaScript: declaring and defining a function separately?

If I want to give a JavaScript variable global scope I can easily do this: var myVar; function functionA() { myVar = something; } Is there a similarly simple and clean way -- without creating an object -- to separate the "declaring" and the "defining" of a nested function? Something like: function functionB; // declared wi...

Which is the better convention of declaring pointers in C++? MyClass* ptr (or) MyClass *ptr?

Which is the better convention of declaring pointers in C++? MyClass* ptr (or) MyClass *ptr I find the first one meaningful, because i feel like declaring MyClass pointer rather than a MyClass and specifying a type modifier. But i see a lot of books recommending the later convention. Can you give the rational behind the convention...

Assign multiple values to array in C

Is there any way to do this in a condensed form? GLfloat coordinates[8]; ... coordinates[0] = 1.0f; coordinates[1] = 0.0f; coordinates[2] = 1.0f; coordinates[3] = 1.0f; coordinates[4] = 0.0f; coordinates[5] = 1.0f; coordinates[6] = 0.0f; coordinates[7] = 0.0f; return coordinates; Something like coordinates = {1.0f, ...};? ...

The C++ Programming language, Definitions vs Declarations exercise (simple, if tedious help needed XD).

Hi there. I've been working through Bjarne Stroustrup's "The C++ Programming Language" (2nd edition - I know I should really get a new copy but this is a library book!), and had a few questions about one of his simpler questions. In Chapter 2, when talking about Declarations and Constants, he lists a set of declarations, some of which ar...

what is the expected behavior?

Below is a purely academically invented class hierarchy. struct X{ void f1(); void f2(); void f3(); }; struct Y : private X{ void f4(); }; struct Z : X{ }; struct D : Y, Z{ using X::f2; using Z::X::f3; }; int main(){} I expected using declaration for X::f2 to be ambiguous as 'X' is a...

C++ const reference declaration

how can the following declaration be expressed with const first (without typedef)? double* const (&data)[6] // ?? const double* (&data)[6] // incorrect, elements, not reference, are const thank you ...

Howto declare variable and use it in the same SQL script?

Hi everybody, I am doing some tests here and write some SQLs. I try to write some reusable code and therefore I want to declare some variables at the beginning and reuse them in the script, like this: DEFINE stupidvar = 'stupidvarcontent'; SELECT stupiddata FROM stupidtable WHERE stupidcolumn = &stupidvar; I tried so far: Use a DEC...

Different declaration and definition in c++

Hi, I'm a bit hazy on the rules of declarations vs. definitions. I have the following declaration in funcs.h: void sumTotalEnrgyAndClush(Protein &A,Protein &B,double ans[2],double enrgyA[18][18],double enrgyB[18][18]); Notice that ans[2] is before enrgyA and B. In the funcs.cpp file the definition starts like this: void sumTot...

java class declaration <T>

hi all it's simple class declaration public class test but i don't understand it public class test<T> . ...

Efficient Declaration/Creation of variables/controls.

I'm working on cleaning up an app I'm almost finished with and I noticed something that made me curious as to why it's being done that way. While you can edit the .Designer.cs in your project for a form, there is a lot of autogenerated stuff in there, such as the creation of variables and controls. They have the Windows Form Designer g...