declaration

Ruby Terminology Question: Is this a Ruby declaration, definition and assignment, all at the same time?

If I say: x = "abc" this seems like a declaration, definition and assignment, all at the same time, regardless of whether I have said anything about x in the program before. Is this correct? I'm not sure what the correct terminology is in Ruby for declarations, definitions and assigments or if there is even a distinction between thes...

Why should I initialize member variables in the constructor?

Something I've been taught when I first started with Object Oriented programming languages. When declaring a field in a class, don't initialize it yet, do that in the constructor. In C#: public class Test { private List<String> l; public Test() { l = new List<String>(); } } But when someone recently asked me why to do t...

Can C++ method names be qualified by the class name, in the header?

Hi. Simple question, is this valid C++: class Foo { void Foo::doSomething(); }; The point of the question: is that repeated use of the class name and double colon before the method name valid inside the class declaration? I'm having issues compiling code that does this using g++ 4.2.3. I would love to see a reference to somethin...

Declaring Multiple Variables in JavaScript

Hello, In JavaScript, it is possible to declare multiple variables like this: var variable1 = "Hello World!"; var variable2 = "Testing..."; var variable3 = 42; ...or like this: var variable1 = "Hello World!", variable2 = "Testing...", variable3 = 42; Is one method better/faster than the other? Thanks, Steve ...

Assign value from one associative array of php into another array

I have a variable $params which gets data from the database: $params = mssql_fetch_array($result) As far as I know, it is associative array. I want another array $tempParams to hold the value of this array. Can I assign it by using the following statement: $tempParams = $params In addition, do I need one single statement to decla...

C++ multiple declaration of function error when linking

Hi, I seem to be forgetting my C++ ... I'm trying to declare some functions in C in separate sources, and including the appropriate .h when necessary. It compiles OK; but the problem is during linking, where the linker complains about functions already being defined. I even tried defining the functions as extern, in a (vain) attempt ...

C : differences between prototype declaration in header and function declaration for implementation?

I was wondering about little differences between declaration of function prototypes in headers and in .c files. I have a header with some prototype functions and a some .c files with real implementation of these functions. I made some changes in the header, only added "__restrict" qualifier (recognized by gcc). My question is do I have t...

Meaning of "const" last in a C++ method declaration?

What is the meaning of const in declarations like these? The const confuses me. class foobar { public: operator int () const; const char* foo() const; }; ...

C hard coding an array of typedef struct

This is such a dumb question it's frustrating even asking it. Please, bear with me, I'm feeling particularly dumb over this one today.... I've got a library with a certain typedef struct. basically: typedef struct {int x; int y;} coords; What I really wanted to do was declare in my header a variable array of this: coords MyCoord...

In C++ classes, why the semi-colon after the closing brace

Apologies in advance for what is probably a stupid question, but in C++ classes, why the semi-colon after the closing brace? I regularly forget it and get compiler errors, and hence lost time. Seems somewhat superfluous to me, which is unlikely to be the case. Do people really do things like class MyClass { . . . } MyInstance; Edit...

Declaring a variable before initializing it in c++

Is it possible to declare a variable in c++ without instantiating it? I want to do something like this: Animal a; if( happyDay() ) a( "puppies" ); //constructor call else a( "toads" ); Basially, I just want to declare a outside of the conditional so it gets the right scope. Is there any way to do this without using pointers ...

How do I pass a hash to a function in Perl?

I am having a lot of trouble. I have a function that takes a variable and an associative array, but I can't seem to get them to pass right. I think this has something to do with function declarations, however I can't figure out how they work in Perl. Does anyone know a good reference for this and how to accomplish what I need? I should a...

Can I place ASP.NET user controls on pages without a control declaration?

I would like to put user controls on pages without registering the tag at the top of the page. For example: <p>some text</p> <myname:mycontrol runat="server" /> Is this possible? I've heard that tag declarations can be done in web.config... is this true? If so, any idea which .NET framework versions support this? Thanks ...

Why does my .push_back() give me an error? (C++)

I initialized a vector of pointers called "antiviral_data", and am able to use antiviral_data.push_back without problems. But when I try to do the same thing with "viral_data" I get an error, because the compiler thinks I am redeclaring "viral_data": vector<virus*> viral_data; vector<virus*>::iterator vI; viral_data.push_back(new X1(9, ...

C# Designer error

Hello, I'm a newbie to C# so please excuse me if I ask dumb questions... Here is my problem : I have a class "ProtocolTabPage" that inherits from "TabPage". I have a "ControlPanel" that inherits from "Panel". I have a ControlPanel instanced by my ProtocolTabPage. Both my classes are in the namespace "AutoTestProtocols.Interface". I...

Is it possible to declare a class without defining it? (C++)

I know the questions seems ambiguous, but I couldn't think of any other way to put it, but, Is it possible to do something like this: #include<iostream> class wsx; class wsx { public: wsx(); } wsx::wsx() { std::cout<<"WSX"; } ? ...

C++ Class Declaration

Why does the following program give me an declaration error? Aren't I declaring it at that specific line? #include <iostream> #define MILLION 1000000 using namespace std; class BitInt { public: BigInt(); private: int digit_array[MILLION]; int length; }; BigInt::BigInt() { int length=0; for(int i=0; i<MILLIO...

declare a array of const ints in C++

Hi, I have a class and I want to have some bit masks with values 0,1,3,7,15,... So essentially i want to declare an array of constant int's such as: class A{ const int masks[] = {0,1,3,5,7,....} } but the compiler will always complain. I tried: static const int masks[] = {0,1...} static const int masks[9]; // then initializing ...

What’s the difference between "Array()" and "[]" while declaring a JavaScript array?

Whats the real difference between declaring an array like this: var myArray = new Array(); and var myArray = []; ...

C++ overloaded operator declaration and definition problems

I am having a hard time getting this to work file: myclass.hpp Class MyClass { public: template <class T> MyClass &operator<<(const T &val); }; file: myclass.cpp template <class T> MyClass &MyClass::operator<<(const T &val) { ... } I can compile this in to a object without a problem, But when other functions try to ca...