reference

Why does the compiler allow a function to return a value that is stored as a reference

Can anybody explain why this code does not generate a compiler error? class Foo { public: int _x; }; Foo getFoo() { Foo myfoo; myfoo._x = 10; return myfoo; } int _tmain() { // shouldn't this line of code be a compiler error? Foo& badfoo = getFoo(); return 0; } ...

Difference between const reference and normal parameter

void DoWork(int n); void DoWork(const int &n); Whats the diff ...

C++: get const or non-const reference type from trait

I am writing a functor F which takes function of type void (*func)(T) and func's argument arg. template<typename T> void F(void (*func)(T), WhatTypeHere? arg) { func(arg); } Then functor F calls func with arg. I would like F not to copy arg, just to pass it as reference. But then I cannot simply write "void F(void (*func)(T), T&)"...

Why `A & a = a` is valid?

#include <iostream> #include <assert.h> using namespace std; struct Base { Base() : m_member1(1) {} Base(const Base & other) { assert(this != &other); // this should trigger m_member1 = other.m_member1; } int m_member1; }; struct Derived { Derived(Base & base) : m_base(m_base) {} // m_base(base) Base & m_...

Is it possible to reinterpret pointer as dimensioned array reference?

hi. Suppose I have some pointer, which I want to reinterpret as static dimension array reference: double *p; double (&r)[4] = ?(p); // some construct? // clarify template< size_t N> void function(double (&a)[N]); ... double *p; function(p); // this will not work. // I would like to cast p as to make it appear as double[N] Is it p...

int foo(type& bar); is a bad practice?

Well, here we are. Yet another proposed practice that my C++ book has an opinion on. It says "a returning-value(non-void) function should not take reference types as a parameter." So basically if you were to implement a function like this: int read_file(int& into){ ... } and used the integer return value as some sort of error indic...

Why do some people prefer "T const&" over "const T&"?

So, I realize that const T& and T const& are identical and both mean a reference to a const T. In both cases, the reference is also constant (references cannot be reassigned, unlike pointers). I've observed, in my somewhat limited experience, that most C++ programmers use const T&, but I have come across a few people who use T const&. I ...

object won't die (still references to it that I can't find)

I'm using parallel-python and start a new job server in a function. after the functions ends it still exists even though I didn't return it out of the function (I used weakref to test this). I guess there's still some references to this object somewhere. My two theories: It starts threads and it logs to root logger. My questions: can I...

How to load an external swf to the main stage from an instanced child class?

Hi, I am trying to get an instance of a class to the load an external swf and show it. So far I have the following: 1) I wrote a class that uses the Loader class to load an external swf "loadExtSWF". 2) I have a fla named "MainSWF.fla" that uses a document class "MainSWF.as". 3) I have the MainSWF.as file that instances "loadExtSWF" an...

Variable reference problem when loading an object from a file in Java

I have a problem with the reference of a variable when loading a saved serialized object from a data file. All the variables referencing to the same object doesn't seem to update on the change. I've made a code snipped below that illustrates the problem. Tournament test1 = new Tournament(); Tournament test2 = test1; try { ...

In laymans terms, what does 'static' mean in Java?

I have been told several definitions for it, looked on Wikipedia, but as a beginner to Java I'm still not sure what it means. Anybody fluent in Java and idiot? Thanks in advance ...

ASP.NET "Object reference not set..." error

Hi, I have a website written using ASP.NET. We have a development machine and a deployment server. The site works great on the development machine, but when is transfered (using simple FTP Upload) generates strange behavior. It starts working just fine, but after a while stops working and throws an exception "Exception: Object reference ...

Problem with relative path to image in XAML?

I am trying to reference a PNG file in my applications working directory through XAML with the following: <Image Name="contactImage"> <Image.Source> <BitmapImage UriSource="/Images/contact.png"> </Image.Source> </Image> Now in my code-behind I try to get the height of the image with contactImage.Source.Height This fai...

Fluent NHibernate - Set reference key columns to null

Hi, I have a table of Appointments and a table of AppointmentOutcomes. On my Appointments table I have an OutcomeID field which has a foreign key to AppointmentOutcomes. My Fluent NHibernate mappings look as follows; Table("Appointments"); Not.LazyLoad(); Id(c => c.ID).GeneratedBy.Assigned(); Map(c => ...

Remove PostSharp reference after build?

Is is possible to get postsharp to remove references to the postsharp assemblies during a build? I have an exe i needs to have a very small footprint. I want to use some of the compile time weaving of postsharp but dont want to have to deploy PostSharp.dll with the exe. I am using PostSharp 2 (2.0.4.1074 specifically) ...

Write-Only Reference in C++?

Is there a way to code a write-only reference to an object? For example, suppose there was a mutex class: template <class T> class mutex { protected: T _data; public: mutex(); void lock(); //locks the mutex void unlock(); //unlocks the mutex T& data(); //returns a reference to the data, or throws an exception if lock is ...

C++ reference variables

I have these two functions (with Point2D & LineVector (has 2 Point2D member variables) classes and SQUARE macro predefined) inline float distance(const Point2D &p1,const Point2D &p2) { return sqrt(SQUARE(p2.getX()-p1.getX())+SQUARE(p2.getY()-p1.getY())); } inline float maxDistance(const LineVector &lv1,const LineVector &lv2) { ...

Referencing dlls built with older .Net versions

In a project using .Net4 - should there be any issues referencing dlls built for older versions of .Net? We're talking 3rd Party dlls here. I'm asking this as a general question. Specifically I have a problem referencing FluentNHibernate.dll - built with .Net3.5. It worked justed fine before I updated my project from .Net3.5 to .Net4. ...

Approximate Number of CPU Cycles for Various Operations

I am trying to find a reference for approximately how many CPU cycles various operations require. I don't need exact numbers (as this is going to vary between CPUs) but I'd like something relatively credible that gives ballpark figures that I could cite in discussion with friends. As an example, we all know that floating point division...

References To Develop GUI Using PPCompiler

I'm starting to play around with PPCompiler, that is a onboard Pascal compiler for Palm OS, but I want to know where could I get some reference to build GUI applications, with textboxes and these things. Reference = Like those help files with many resources and examples ...