Search Results

Search found 6753 results on 271 pages for 'forward declaration'.

Page 13/271 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Is there a difference between only <NSXMLParserDelegate>, only setDelegate method, or the use of bot

    - by gotye
    Hey, I noticed that when I do this : [myParser setDelegate:self]; it works :D (even if I didn't add the code in the header file ... you know, the <delegateStuff, delegateOtherStuff> in the interface declaration) When are you supposed to modify the header file to make your delegate work ? Is the setDelegate method enough to make it work ? Cheers for any help ;) Gauthier

    Read the article

  • Microsoft C Compiler: Inline variable declaration?

    - by Rosarch
    I'm writing C in Visual Studio 2010. The compiler doesn't seem to want to let me use inline variable declarations. The following code produces an error: unsigned int fibonacci_iterative(unsigned int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } unsigned int prev_prev = 0; // error unsigned int prev = 1; // error unsigned int next = 0; // error for (int term_number = 0; term_number < n; term_number++) { unsigned int temp = prev_prev + prev; prev = next; prev_prev = prev; next = temp; } return next; } Error: error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' Why is this happening? Is there a setting to make the compiler not so strict?

    Read the article

  • Strange declaration(templates). C++

    - by atch
    Hi, guys could anyone explain to my like to a not very inteligent child what is declared here: (this is taken from another post on this forum) template<typename C> static char (&f(ChT<int Fallback::*, &C::x>*))[1]; how I read it is: template of static function f called with (ChT*) but then I can't make sense why is there address of operator and why is there array? When explaining please picture not very inteligent child and then try to make it clear to it. Thanks for any help

    Read the article

  • Creating Haskell instance declarations

    - by btl
    Hello, complete noob to Haskell here with probably an even noobier question. I'm trying to get ghci output working and am stuck on instance declarations. How could I declare an instance for "(Show (Stack - Stack))" given: data Cmd = LD Int | ADD | MULT | DUP deriving Show type Prog = [Cmd] type Stack = [Int] type D = Stack -> Stack I've been trying to create a declaration like: instance Show D where show = Stack but all my attempts have resulted in illegal instance declarations. Any help and/or references much appreciated!

    Read the article

  • java looping - declaration of a Class outside / inside the loop

    - by lisak
    when looping, for instance: for ( int j = 0; j < 1000; j++) {}; and I need to instantiate 1000 objects, how does it differ when I declare the object inside the loop from declaring it outside the loop ?? for ( int j = 0; j < 1000; j++) {Object obj; obj =} vs Object obj; for ( int j = 0; j < 1000; j++) {obj =} It's obvious that the object is accessible either only from the loop scope or from the scope that is surrounding it. But I don't understand the performance question, garbage collection etc. What is the best practice ? Thank you

    Read the article

  • What's your preferred pointer declaration style, and why?

    - by Owen
    I know this is about as bad as it gets for "religious" issues, as Jeff calls them. But I want to know why the people who disagree with me on this do so, and hear their justification for their horrific style. I googled for a while and couldn't find a style guide talking about this. So here's how I feel pointers (and references) should be declared: int* pointer = NULL; int& ref = *pointer; int*& pointer_ref = pointer; The asterisk or ampersand goes with the type, because it modifies the type of the variable being declared. EDIT: I hate to keep repeating the word, but when I say it modifies the type I'm speaking semantically. "int* something;" would translate into English as something like "I declare something, which is a pointer to an integer." The "pointer" goes along with the "integer" much more so than it does with the "something." In contrast, the other uses of the ampersand and asterisk, as address-of and dereferencing operators, act on a variable. Here are the other two styles (maybe there are more but I really hope not): int *ugly_but_common; int * uglier_but_fortunately_less_common; Why? Really, why? I can never think of a case where the second is appropriate, and the first only suitable perhaps with something like: int *hag, *beast; But come now... multiple variable declarations on one line is kind of ugly form in itself already.

    Read the article

  • Setting javascript prototype function within object class declaration

    - by Tauren
    Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param) { this.member = param; } Container.prototype.stamp = function (string) { return this.member + string; } var container1 = new Container('A'); alert(container1.member); alert(container1.stamp('X')); This code produces two alerts with the values "A" and "AX". I'd like to define the prototype function INSIDE of the class definition. Is there anything wrong with doing something like this? function Container(param) { this.member = param; if (!Container.prototype.stamp) { Container.prototype.stamp = function() { return this.member + string; } } } I was trying this so that I could access a private variable in the class. But I've discovered that if my prototype function references a private var, the value of the private var is always the value that was used when the prototype function was INITIALLY created, not the value in the object instance: Container = function(param) { this.member = param; var privateVar = param; if (!Container.prototype.stamp) { Container.prototype.stamp = function(string) { return privateVar + this.member + string; } } } var container1 = new Container('A'); var container2 = new Container('B'); alert(container1.stamp('X')); alert(container2.stamp('X')); This code produces two alerts with the values "AAX" and "ABX". I was hoping the output would be "AAX" and "BBX". I'm curious why this doesn't work, and if there is some other pattern that I could use instead.

    Read the article

  • best practice on precedence of variable declaration and error handling in C

    - by guest
    is there an advantage in one of the following two approaches over the other? here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn't have had to void func(void) { FILE *fd; if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } int a, b, c; float d, e, f; /* variable declarations */ /* remaining code */ } this is just the opposite. all variable declarations take place, even if fopen fails void func(void) { FILE *fd; int a, b, c; float d, e, f; /* variable declarations */ if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } /* remaining code */ } does the second approach produce any additional cost, when fopen fails? would love to hear your thoughts!

    Read the article

  • Declaration, allocation and assignment of an array of pointers to function pointers

    - by manneorama
    Hello Stack Overflow! This is my first post, so please be gentle. I've been playing around with C from time to time in the past. Now I've gotten to the point where I've started a real project (a 2D graphics engine using SDL, but that's irrelevant for the question), to be able to say that I have some real C experience. Yesterday, while working on the event system, I ran into a problem which I couldn't solve. There's this typedef, //the void parameter is really an SDL_Event*. //but that is irrelevant for this question. typedef void (*event_callback)(void); which specifies the signature of a function to be called on engine events. I want to be able to support multiple event_callbacks, so an array of these callbacks would be an idea, but do not want to limit the amount of callbacks, so I need some sort of dynamic allocation. This is where the problem arose. My first attempt went like this: //initial size of callback vector static const int initial_vecsize = 32; //our event callback vector static event_callback* vec = 0; //size static unsigned int vecsize = 0; void register_event_callback(event_callback func) { if (!vec) __engine_allocate_vec(vec); vec[vecsize++] = func; //error here! } static void __engine_allocate_vec(engine_callback* vec) { vec = (engine_callback*) malloc(sizeof(engine_callback*) * initial_vecsize); } First of all, I have omitted some error checking as well as the code that reallocates the callback vector when the number of callbacks exceed the vector size. However, when I run this code, the program crashes as described in the code. I'm guessing segmentation fault but I can't be sure since no output is given. I'm also guessing that the error comes from a somewhat flawed understanding on how to declare and allocate an array of pointers to function pointers. Please Stack Overflow, guide me.

    Read the article

  • Using 'or' in Java Generics declaration

    - by Shervin
    I have a method that returns an instance of Map<String, List<Foo>> x(); and another method that returns an instance of Map<String, Collection<Foo>> y(); Now if I want to dynamically add one of this Maps in my field, how can I write the generics for it to work? ie: public class Bar { private Map<String, ? extends Collection<Foo>> myMap; public void initializer() { if(notImportant) myMap = x(); //OK else myMap = y(); // !OK (Need cast to (Map<String, ? extends Collection<Foo>>) } Now is it ok that I cast to the signature even though the y() is declared as being Collection? } } If it is not ok to cast, can I somehow write this (Collection OR List) I mean, List is a Collection, so it should somehow be possible. private Map<String, Collection<Foo> | List<Foo>>> myMap;

    Read the article

  • What would be different in Java if Enum declaration didn't have the recursive part

    - by atamur
    Please see http://stackoverflow.com/questions/211143/java-enum-definition and http://stackoverflow.com/questions/3061759/why-in-java-enum-is-declared-as-enume-extends-enume for general discussion. Here I would like to learn what exactly would be broken (not typesafe anymore, or requiring additional casts etc) if Enum class was defined as public class Enum<E extends Enum> I'm using this code for testing my ideas: interface MyComparable<T> { int myCompare(T o); } class MyEnum<E extends MyEnum> implements MyComparable<E> { public int myCompare(E o) { return -1; } } class FirstEnum extends MyEnum<FirstEnum> {} class SecondEnum extends MyEnum<SecondEnum> {} With it I wasn't able to find any benefits in this exact case. PS. the fact that I'm not allowed to do class ThirdEnum extends MyEnum<SecondEnum> {} when MyEnum is defined with recursion is a) not relevant, because with real enums you are not allowed to do that just because you can't extend enum yourself b) not true - pls try it in a compiler and see that it in fact is able to compile w/o any errors PPS. I'm more and more inclined to believe that the correct answer here would be "nothing would change if you remove the recursive part" - but I just can't believe that.

    Read the article

  • Javascript Namespace Declaration

    - by objektivs
    What neat ways do you use for declaring JavaScript namespaces. I've come across this one: if (Foo == null || typeof(Foo) != "object") { var Foo = new Object();} Is there a more elegant or succinct way of doing this? Just a bit of fun...

    Read the article

  • storing an integral value in a pointer variable while declaration

    - by benjamin button
    int main() { int *d=0; printf("%d\n",*d); return 0; } this works fine. >cc legal.c > ./a.out 0 if i change the statement int *d=0; to int *d=1; i see the error. cc: "legal.c", line 6: error 1522: Cannot initialize a pointer with an integer constant other than zero. so its obvious that it will allow only zero.i want to know what happens inside the memory when we do this int *d=0 which is making it valid syntax. I am just asking this out of curiosity!

    Read the article

  • Jump to function declaration in php

    - by aeonsleo
    HI, I have the following ide's for php Dreamweaver php-Eclipse Textpad I wish to jump to a function's definition which is located in another file which is not yet open. How could I do that. I am studying a websites code and have the entire directory struction in my local root folder. I come accross certain functions and I dont know in which file their definition is. Pls suggest something.Thanks

    Read the article

  • Jsp declaration element

    - by Stardust
    <%! class father { static int s = 0; } %> <% father f1 = new father(); father f2 = new father(); f1.s++; out.println(f2.s); // It must print "1" %> When I run the file, I got this error. Can anybody explain? "The field s cannot be declared static; static fields can only be declared in static or top level types"

    Read the article

  • JavaScript Namespace Declaration

    - by Hery
    I created a javascript class as follow: var MyClass = (function() { function myprivate(param) { console.log(param); } return { MyPublic : function(param) { myprivate(param); } }; })(); MyClass.MyPublic("hello"); The code above is working, but my question is, how if I want to introduce namespace to that class. Basically I want to be able to call the class like this: Namespace.MyClass.MyPublic("Hello World"); If I added Namespace.MyClass, it'll throw error "Syntax Error". I did try to add "window.Namespace = {}" and it doesn't work either. Thanks.. :)

    Read the article

  • typedef declaration syntax

    - by mt_serg
    Some days ago I looked at boost sources and found interesting typedef. There is a code from "boost\detail\none_t.hpp": namespace boost { namespace detail { struct none_helper{}; typedef int none_helper::*none_t ; } // namespace detail } // namespace boost I didn't see syntax like that earlier and can't explain the sense of that. This typedef introduces name "none_t" as pointer to int in boost::detail namespace. What the syntax is? And what difference between "typedef int none_helper::*none_t" and for example "typedef int *none_t" ?

    Read the article

  • Type Declaration - Pointer Asterisk Position

    - by sahs
    Hello, in C++, the following means "allocate memory for an int pointer": int* number; So, the asterisk is part of the variable type; without it, that would mean something else (that's why I usually don't separate the asterisk from the variable type). Then what is the reason the asterisk is considered something else, instead of being part of the type? For example, it seems better, if the following meant "allocate memory for two int pointers": int* number1, number2; Am I wrong?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >