Search Results

Search found 5015 results on 201 pages for 'compiler construction'.

Page 151/201 | < Previous Page | 147 148 149 150 151 152 153 154 155 156 157 158  | Next Page >

  • C++ rvalue temporaries in template

    - by aaa
    hello. Can you please explain me the difference between mechanism of the following: int function(); template<class T> void function2(T&); void main() { function2(function()); // compiler error, instantiated as int & const int& v = function(); function2(v); // okay, instantiated as const int& } is my reasoning correct with respect to instantiation? why is not first instantiated as const T&? Thank you

    Read the article

  • Delegate Example From C# In Depth Confusion

    - by ChloeRadshaw
    I am looking at this example: List<Product> products = Product. GetSampleProducts() ; products.Sort( (first, second) => first.Name.CompareTo(second. Name) ) ; foreach (Product product in products) { Console. WriteLine(product) ; } What function is actually called in the API when you do that? Does the compiler create a class which implemnents the IComparer interface? I thought delegates were anonymous methods - Here it seems to be an anonymous interface implementation which is casuing confusion

    Read the article

  • Is new int[10]() valid c++?

    - by Naveen
    While trying to answer this question I found that the code int* p = new int[10](); compiles fine with VC9 compiler and initializes the integers to 0. So my questions are: First of all is this valid C++ or is it a microsoft extension? Is it guaranteed to initialize all the elements of the array? Also, is there any difference if I do new int; or new int();? Does the latter guarantee to initialize the variable?

    Read the article

  • Why does Generic class signature requires specifying new() if type T needs instantiation ?

    - by this. __curious_geek
    I'm writing a Generic class as following. public class Foo<T> : where T : Bar, new() { public void MethodInFoo() { T _t = new T(); } } As you can see the object(_t) of type T is instantiated at run-time. To support instantiation of generic type T, language forces me to put new() in the class signature. I'd agree to this if Bar is an abstract class but why does it need to be so if Bar standard non-abstract class with public parameter-less constructor. compiler prompts following message if new() is not found. Cannot create an instance of the variable type 'T' because it does not have the new() constraint

    Read the article

  • C++ standard: dereferencing NULL pointer to get a reference?

    - by shoosh
    I'm wondering about what the C++ standard says about code like this: int* ptr = NULL; int& ref = *ptr; int* ptr2 = &ref; In practice the result is that ptr2 is NULL but I'm wondering, is this just an implementation detail or is this well defined in the standard? Under different circumstances a dereferencing of a NULL pointer should result in a crash but here I'm dereferencing it to get a reference which is implemented by the compiler as a pointer so there's really no actual dereferencing of NULL.

    Read the article

  • hook to save action in eclipse plugin

    - by 4485670
    I want to create a Google Closure Compiler plugin for eclipse. I already have a popup menu entry to compile a Javascript file to its minified version. But it would be more than helpful if every time you save a *.js that minified version would be generated automatically. I read/heard about natures and builders, extension points and IResourceChangeListener. But I did not manage to figure out what I should use and especially how to get it to work. Is there a working example of a plugin that does "the same kind of thing" so I can work from that or a tutorial to write such? With the answer below I searched for projects that use the IResourceChangeListener and came up with this code: manifest: http://codepaste.net/3yahwe plugin.xml: http://codepaste.net/qek3rw activator: http://codepaste.net/s7xowm DummyStartup: http://codepaste.net/rkub82 MinifiedJavascriptUpdater: http://codepaste.net/koweuh There in the MinifiedJavascriptUpdater.java which holds the code for the IResourceChangeListener the "resourceChanged" function is never reached.

    Read the article

  • Why does a non-constant offsetof expression work?

    - by Chris J. Kiick
    Why does this work: #include <sys/types.h> #include <stdio.h> #include <stddef.h> typedef struct x { int a; int b[128]; } x_t; int function(int i) { size_t a; a = offsetof(x_t, b[i]); return a; } int main(int argc, char **argv) { printf("%d\n", function(atoi(argv[1]))); } If I remember the definition of offsetof correctly, it's a compile time construct. Using 'i' as the array index results in a non-constant expression. I don't understand how the compiler can evaluate the expression at compile time. Why isn't this flagged as an error?

    Read the article

  • How to strip debug code during compile time in C++?

    - by juvenis
    Say I have a C++ function debugPrint(int foo). How can I most conveniently strip that from release builds? I do not want to surround every call to debugPrint with #ifdefs as it would be really time consuming. On the other hand, I want to be 100% sure that the compiler strips all the calls to that function, and the function itself from release builds. The stripping should happen also, if it's called with a parameter that results from a function call. E.g., debugPrint(getFoo());. In that case I want also the getFoo() call to be stripped. I understand that function inlining could be an option, but inlining is not guaranteed to be supported.

    Read the article

  • How to explain to a developer that adding extra if - else if conditions is not a good way to "improv

    - by Lilit
    Recently I've bumped into the following C++ code: if (a) { f(); } else if (b) { f(); } else if (c) { f(); } Where a, b and c are all different conditions, and they are not very short. I tried to change the code to: if (a || b || c) { f(); } But the author opposed saying that my change will decrease readability of the code. I had two arguments: 1) You should not increase readability by replacing one branching statement with three (though I really doubt that it's possible to make code more readable by using else if instead of ||). 2) It's not the fastest code, and no compiler will optimize this. But my arguments did not convince him. What would you tell a programmer writing such a code? Do you think complex condition is an excuse for using else if instead of OR?

    Read the article

  • XCode Project Code Changes Not Updating 100% After Save-Build-Run

    - by Greg
    When I make code changes to my iPhone game project in XCode, and then do CMD-B + Enter, I expect the project to be saved, build and run on the simulator with the latest. What is happening though, sometimes, is that it doesn't pick up a small change I make unless I clean the project and then build. I'm a long time Java person and newish to C-based languages and it's compiler. Can someone explain to me what is cached after each build that does this and how to change my project settings to avoid having to clean everytime? Or tell me the bad news that this is part of C development? Not trying to bash it - I get compiled JSPs stuck in the working cache often in Java, too. :P

    Read the article

  • Problem with non-copyable classes

    - by DeadMG
    I've got some non-copyable classes. I don't invoke any of the copy operators or constructor, and this code compiles fine. But then I upgraded to Visual Studio 2010 Ultimate instead of Professional. Now the compiler is calling the copy constructor- even when the move constructor should be invoked. For example, in the following snippet: inline D3D9Mesh CreateSphere(D3D9Render& render, float radius, float slices) { D3D9Mesh retval(render); /* ... */ return std::move(retval); } Error: Cannot create copy constructor, because the class is non-copyable. However, I quite explicitly moved it.

    Read the article

  • Strange macro declaration in C

    - by Andrey Atapin
    Exploring libusb-1.0.9 source code, I have found such line (./os/poll_windows.c:78): #define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0) As for me this is the same like: #define CHECK_INIT_POLLING if(!is_polling_set) init_polling(); Is there any reason to loop that expression? UPDATE: I couldn't still realize what'd be wrong after the answers, and the following example helped: #include <stdio.h> #define TEST if(test) foo(); #define TEST_DO do { if(test) foo(); } while(0) int test = 1; void foo() { printf("%s", "Foo called"); } int main(int argc, char** argv) { if(argc > 1) TEST_DO; /* LINE 12 */ else printf("%s", "skipping..."); return 0; } If you put TEST at line 12, a compiler will give an error "error: ‘else’ without a previous ‘if’". Hope, this will help someone.

    Read the article

  • Typecasting doesn't work. How to convert an object?

    - by Nastase Ion
    Hi everyone! I need to convert a custom object to a different object. How can I do that? I know that typecasting doesn't work (the only thing is does is "shuts the compiler warnings off", but nothing more). Here is a sample code: MyType* obj1; MyOtherType* obj2; obj1 = [MyType initWithData: 1]; obj2 = (MyOtherType*) obj1; if ([obj2 isMemberOfClass: [MyOtherType class]]) { NSLog(@"OK"); } else if ([obj2 isMemberOfClass: [MyType class]]) { NSLog(@"Nope"); } The result is: Nope What can I do??

    Read the article

  • I want to make a wrapped acces type for certain internals of one of classes and I have some performa

    - by Alex
    I am writing an abstract matrix class (and some concrete subclasses) for use on very differing hardwares/architectures, etc. and I want to write a row and column type that provides a transparent reference to the rows and columns of the matrix. However, I want to tune for performance, so I'd like this class to be essentially a compiler construct. In other words, I'm willing to sacrifice some dev time to making the overhead of these classes as small as possible. I assume all (small) methods would want to be virtual? Keep the structure small? Any other suggestions?

    Read the article

  • Why Do try ... catch Blocks Require Braces?

    - by Bidou
    Hello. While in other statements like if ... else you can avoid braces if there is only one instruction in a block, you cannot do that with try ... catch blocks: the compiler doesn't buy it. For instance: try do_something_risky(); catch (...) std::cerr << "Blast!" << std::endl; With the code above, g++ simply says it expects a '{' before do_something_risky(). Why this difference of behavior between try ... catch and, say, if ... else ? Thanks!

    Read the article

  • Should I use C(99) booleans ? ( also c++ booleans in c++ ?)

    - by Roman A. Taycher
    I haven't done much c programming but when I do when I need a false I put 0 when I want true I put 1, (ex. while(1)), in other cases I use things like "while(ptr)" or "if(x)". Should I try using C99 booleans, should I recommend them to others if I'm helping people new to programming learn c basics(thinking of cs 1?? students)? I'm pretty sure the Visual Studio compiler supports c99 bools, but do a lot of projects (open source and c apps in industry) compile for c89? If I don't use C bools should I at least do something like #define TRUE 1 #define FALSE 0? Also what about c++ Booleans (for c++)?

    Read the article

  • What's the outcome if I use free with new or delete with malloc?

    - by skydoor
    It is a compiler error or runtime error? The code below can be compiled! class Base{ void g(); void h(); }; int main() { Base* p = new Base(); free(p); return 0; } However it can't be compiled with a virtual function if I declare the class Base like this class Base{ virtual void g(); void h(); }; The code below can be compiled all the time, no matter the function is virtual or not. class Base{ void g(); void h(); }; int main() { Base* p = (Base*)malloc(sizeof(Base)); delete p; return 0; }

    Read the article

  • Isses using function with variadic arguments

    - by Sausages
    I'm trying to write a logging function and have tried several different attempts at dealing with the variadic arguments, but am having problems with all of them. Here's the latest: - (void) log:(NSString *)format, ... { if (self.loggingEnabled) { va_list vl; va_start(vl, format); NSString* str = [[NSString alloc] initWithFormat:format arguments:vl]; va_end(vl); NSLog(format); } } If I call this like this: [self log:@"I like: %@", @"sausages"]; Then I get an EXC_BAD_ACCESS at the NSLog line (there's also a compiler warning that the format string is not a string literal). However if in XCode's console I do "po str" it displays "I like: sausages" so str seems ok.

    Read the article

  • int vs const int&

    - by Valdo
    I've noticed that I usually use constant references as return values or arguments. I think the reason is that it works almost the same as using non-reference in the code. But it definitely takes more space and function declarations become longer. I'm OK with such code but I think some people my find it a bad programming style. What do you think? Is it worth writing const int& over int? I think it's optimized by the compiler anyway, so maybe I'm just wasting my time coding it, a?

    Read the article

  • C# Generics Multiple Inheritance Problem

    - by Ciemnl
    Can any one help me with this syntax issue with C#? I have no idea how to do it. class SomeClass<T> : SomeOtherClass<T> where T : ISomeInterface , IAnotherInterface { ... } I want SomeClass to inherit from SomeOtherClass and IAnotherInterface and for T to inherit ISomeInterface only It seems the problem is that the where keyword screws everything up so that the compiler thinks both ISomeInterface and IAnotherInterface should both be inherited by T. This problem is very annoying and I think the solution is some kind of parenthesis but I have tried and failed finding one that works. Also, switching around the order of the two items inherited from SomeClass does not work because the class inherited always has to come before any interfaces. I couldn't find any solutions on the MSDN C# generics pages and I can't beleive I'm the first person to have this problem. Thanks, any help is much appreciated!

    Read the article

  • C++ template + typedef

    - by MMS
    What is wrong in the following code: Point2D.h template <class T> class Point2D { private: T x; T y; ... }; PointsList.h template <class T> class Point2D; template <class T> struct TPointsList { typedef std::vector <Point2D <T> > Type; }; template <class T> class PointsList { private: TPointsList <T>::Type points; //Compiler error ... }; I would like to create new user type TPointsList without direct type specification...

    Read the article

  • Is this a valid C statement ?

    - by Philando Gullible
    Lets say I write char c[99] = {'Stack Overflow'}; in C or C++ it does compiles fine but does this valid? By valid I meant not invoking any kind of undefined or unspecified behavior. Again if I write char c[99] = 'Stack Overflow'; gcc complains about multicharacter constant which is obvious but in the above when I am enclosing within curly brackets compiler is happy! why is it so ? I also notice that puts(c); after the first statement will output 'w' precisely the last character of a general string in-place of Stack Overflow. why so ? Could somebody explain this behavior may be separately.

    Read the article

  • Get result type of function

    - by Robert
    I want to specialize a template function declared as: template<typename Type> Type read(std::istream& is); I then have a lot of static implementations static int read_integer(std::istream& is); a.s.o. Now I'd like to do a macro so that specialization of read is as simple as: SPECIALIZE_READ(read_integer) So I figured I'd go the boost::function_traits way and declare SPECIALIZE_READ as: #define SPECIALIZE_READ(read_function) \ template<> boost::function_traits<read_function>::result_type read(std::istream& is) { \ return read_function(is); \ } but VC++ (2008) compiler complains with: 'boost::function_traits' : 'read_integer' is not a valid template type argument for parameter 'Function' Ideas ?

    Read the article

  • Strings in ASP?

    - by TSL
    Hi All, I have some APSX code that I am trying to modify for a programmer that is out on medicaly leave. I am not an ASP guy, but rather C++ So what I want to do is delare a string, check the first 4 characters and if it is 'http' do something, if not, something else. Here is what I have: string strYT= Left(objFile, 4); if (strYT=="http") { pnlYT.Visible = true; pnlIntro.Visible = false; pnlVideo.Visible = false; } else { pnlYT.Visible = false; pnlIntro.Visible = false; pnlVideo.Visible = true; PrintText(objFile); } But I get errors like: Compiler Error Message: CS0103: The name 'Left' does not exist in the class or namespace 'ASP.zen_aspx' My googling turns up many examples of doing it just like this.....

    Read the article

  • question about copy constructor

    - by lego69
    I have this class: class A { private: int player; public: A(int initPlayer = 0); A(const A&); A& operator=(const A&); ~A(); void foo() const; }; and I have function which contains this row: A *pa1 = new A(a2); can somebody please explain what exactly is going on, when I call A(a2) compiler calls copy constructor or constructor, thanks in advance

    Read the article

< Previous Page | 147 148 149 150 151 152 153 154 155 156 157 158  | Next Page >