Dive Deep into CPP: Abstract Class and Pure Virtual Function

Pure virtual function are virtual function with no definition.


virtual void func()=0;

Class with atleast one pure virtual is made as abstract class. Classes that inherit the abstract class must provide the definition to the pure virtual function.

What happens when we create a pure virtual function ?

When we create a pure virtual function in abstract class, we reserve slot for that function in the VTABLE(virtual table, maintained by the compiler), but doesnt put any address in that slot. So the VTABLE will be incomplete.Since the VTABLE for the abstract class is incomplete, compiler will not allow the creation of the object and will throw an error.

Pure Virtual Definitions:

These pure virtual functions can have definition in abstract class, which we want all the derived class to have. These definitions should be provided outside the class definition.

What does pure virtual function mean ?

When a function is declared pure virtual function, it cannot be called dynamically through a virtual dispatch mechanism.But it can be called statically without virtual dispatch. So, yes. Pure virtual functions can have definition. But it makes the class abstract without completing the VTABLE.


Dive Deep into CPP: Copy Constructor

Copy Constructor is usually invoked by passing reference to the old object of a class to a newly created object of the same class. Compiler by default provide a copy constructor to a class even if you didnt provide one. When the Copy Constructor is invoked either by calling copy constructor during declaration or using an assignment operator, the constructor will get the reference and then it simply assigns it to the new object using the assignment operator.So Copy Constructor is implemented by overloading the assignment operator.

Why program runs into an infinite loop , if copy constructor is invoked by value ?

If we didnt pass the old object by reference and if we pass by value, in the copy constructor it will be assigned to the new object by an assignment operator and the compiler will inturn call the copy constructor again and then assignment operator and so on in an infinite loop.

Computers that calculate data at the speed of light could arrive as early as 2020

Most folks know that data travels at much higher speeds and capacities over optical cables than it can over copper equivalents. A prime example is the tremendous transfer speeds available on fiber optic networks, as opposed to copper POTS (plain old telephone service) lines. We’re talking thousands, even millions more times the data.
If you think about it, there’s no reason that the technology (or something similar) that allows us to move massive data around from Point A to Point B shouldn’t help speed up our computers too.
To that end, an English technology company dubbed Optalysys says that in January 2015, it will demonstrate a prototype optical computer that performs calculations at the speed of light. If all goes well, the company says that we will see exascale supercomputers as early as 2020.

What is an optical computer?
The term optical computing can refer to many different types of technologies. Basically, it refers to computers that use light, rather than electricity, to perform many of its tasks.While Optalysys’ approach, which employs low-power lasers and a huge liquid crystal grid, is much different from most other competing optical-based models, the company’s results are very promising so far.
While highly complicated, the Optalysys approach projects low-power lasers onto the liquid crystal grid, which in turn initiates reactions within the grid. This generates sophisticated algorithms, accommodating thousands, even millions of calculations simultaneously. By using multiple grids, either in sequence or in parallel, you can significantly increase capacity and processing power.
In addition to providing massive computing oomph, the Optalysys’ system consumes very little power.The company provided the following statistic to demonstrate the incredible savings in electricity: An optical computer will use roughly $3,500 worth of electricity each year, while today’s most powerful supercomputer, when running at its peak power of 34 petaflops per second, sucks juice at an annual cost of about $21 million.
What could a company do with those kinds of power savings? The truth is that very few companies (Perhaps Google, Microsoft, Amazon, and so on) require supercomputers with that kind of processing oomph. Most of us, on the other hand, would have little use for anywhere close to that kind of computing power.
Still, in addition to reducing the power bill literally by millions, optical computers should also decrease the size of supercomputers themselves drastically, thereby reducing space requirements and a slew of other expenses associated with housing humongous machines. The ability to deliver supercomputer power in a desktop-size machine opens up possibilities in all kinds of areas, including medicine, digital video and other media editing, 3D modeling, CAD—the list goes on and on.If and when optical computers go mainstream, imagine what such a desktop machine would be capable of.

When will we see optical computers?
According to Optalysys, its optical computing technology has already met the NASA Technology Readiness Level (TRL) 4. This means that it’s ready for full-scale lab testing.As mentioned, the company says that we’ll see a prototype by January 2015, and that it hopes to have two commercial demo systems up and running by 2017.
A big data analysis system for augmenting conventional supercomputers, and a standalone “Optical Solver” supercomputer that, a company spokesman says, should start at 9 petaflops, with it scaling up to 17.1 exaflops could arrive by 2020.However, while the technology itself seems sound, Optalysys is just getting started. With this in mind, the 2020 time frame seems ambitious.If all works out as planned though, the next bunch of years could see some freakishly powerful computers.

This app will shut down everything on your phone until you call your mom back

Never underestimate your mom, kids — especially if she learns how to code. Sharon Standifird’s son knows this all too well. He didn’t always answer his mother’s calls as quickly as she might have liked, so she figured out a way to make sure he called her back ASAP when he missed a call. Standifird created her own Android app called Ignore No More, which gives your mom or dad the power to literally shut down every function on your phone — except the ability to call the parental unit back or 911 — until you cave and call them back.

Many teenagers can withstand 10 missed calls from mom without batting an eyelash, but when you take away Facebook, Instagram, Snapchat, and everything else in one fell swoop, most won’t last five minutes without calling dear old mom and dad to beg for their freedom back. Ignore No More does just that.
All parents have to do is set up an account, add their kids, and make sure the app is installed on each child’s device, so that they can remotely control their kids’ smartphones whenever the youngsters don’t answer their calls or messages. To shut down a kid’s phone, mom or dad just need to tap on their son or daughter’s name, enter an unlock code twice, and voila — the unresponsive kid’s phone goes dark. In order to unlock their device, the teen must call one of the people listed on the approved contacts list, which may include anyone the parent chooses.
The only difficult part is getting Ignore No More onto a kid’s phone. Assuming they’ve got a passcode, parents won’t even be able to unlock their kids’ phone, let alone install the app. Even if the kid’s phone is unsecured, parents still have to know the code for purchasing apps on the device to install Ignore No More on the device. This may be easy enough for parents whose kids are still in the house, but those with grown kids or ones in college may have a harder time of it.

Of course, sneaky and clever parents could just stick Ignore No More onto a brand new smartphone, so as to trick their unsuspecting kids into thinking the Trojan horse is a great present.

Ignore No More is available for download on the Google Play Store, but it will cost you $2 for each device you install it on. Standifird says she’s already working on an iOS version of the app, so don’t fret iPhone parents!

Google acquires image-based city guides company Jetpac to improve visual search

Google is continuing its acquisition binge in 2014 with the purchase of Jetpac, an iOS app that uses public information from Instagram photos to create image-driven city maps and guides. The move appears to be a step toward improving the search giant’s visual-search capabilities.
Jetpac’s City Guides app offers users visual guides to local recommendations for bars, views and other hangout spots in more than 6,000 cities around the world. It serves up guides that are tailored to the user’s personal affinities or filtered by categories of places to go. It also has a “Snappyness” rating to show what visitors snap the most photos of at a specific venue.

The app also identifies notable elements in Instagram photos, such as blue skies and mustaches, in order to categorize hangout spots. So, for instance, a spot with a noticeably high number of mustaches in photos is tagged as a “Hipster Hangout.”

Jetpac’s Spotter app, on the other hand, allows users to use their iPhone’s video camera to identify objects in real time. This “deep learning” feature in particular may be a boon for Google’s image search capabilities – for its Google Goggles app, for instance. Meanwhile, the City Guides functionalities may be a nifty implementation for Google+ or Google Maps.

Jetpac has announced the acquisition on its website, noting that its iOS apps will soon be removed from the App Store and that support for its apps will end on Sept. 15.

The terms of the deal have not been disclosed, and Google has yet to confirm the acquisition.

Video on how it works: http://vimeo.com/93190857

Smartphone’s gyroscope can be turned into an eavesdropping hacker’s microphone

If you own a smartphone, chances are it has a gyroscope – and chances also are that gyroscope can be used (without special permissions) as a microphone to listen in on your private conversations. This is the startling finding from two researchers from Stanford University’s Computer Science Department and one researcher from Rafael Advanced Defense Systems, who authored a paper titled “Gyrophone: Recognizing Speech From Gyroscope Signals.”

According to the paper, microelectromechanical systems (MEMS) gyroscopes found in modern smartphones are sensitive enough to pick up acoustic signals. While these raw signals aren’t enough to glean useful information from, the researchers used signal processing and algorithms to identify the correct speaker from a set of 10 possible speakers with a 50 percent success rate.

Using a Nexus 4 and a Galaxy S3, they were also able to successfully recognize simple speech up to 65 percent of the time in speaker-dependent cases and up to 26 percent of the time in speaker-independent cases. The gyroscopes in these phones were also used to correctly identify a speaker’s gender up to 84 percent of the time.

“Since iOS and Android require no special permissions to access the gyro, our results show that apps and active web content that cannot access the microphone can nevertheless eavesdrop on speech in the vicinity of the phone,” according to the paper.
The researchers also offer two suggestions for defending against gyroscope-based eavesdropping: apply low-pass filtering to raw samples provided by the gyroscope, or apply a form of acoustic masking around the gyroscope itself or on a smartphone’s case.

“A general conclusion we suggest following this work is that access to all sensors should be controlled by the permissions framework, possibly differentiating between low and high sampling rates,” according to the researchers.

The paper will be presented at the 23rd USENIX Security Symposium in San Diego on Friday, Aug. 22.

Those interested in downloading an Android application that can be used for sampling a phone’s gyroscope can head to the Stanford Security Research page dedicated to the paper.

Dive Deep into CPP: Types of collaboration between classes

Message to self.Calling m1 from m2 where they are the methods of the same class. Preferred relationship is “has-a “.We will be using “this” keyword for invocation. Which means compiler already created an object of the same class within itself.

Base derived
We can call the method of base class from derived using “super” or “base” keywords which are the objects of base and it is created within the derived class. So we use “is-a” relation but it is implemented through “has-a” relation. But if there is no “is-a” relation between the base and derived class, then those objects won’t be created. So its an equalizer

Accessing from sibling class. Preferred relation  is “has-a”.

Peer to peer
Preferred relationship is “has-a ”

Generalization is having both the interface(type contracts etc) and the implementation of the base class.
Realization is having only the interface of the base class and creating their own implementation for the methods in the base class.
In “has-a” relationship, we can use only the  implementation of the class, but not its interface.
Finally, we can say  generalization =realization +has a
So generalization which is tightly coupled can be replaced with realization and association relationships which will make the classes loosely coupled.This will give the flexibility we need and will give us a good clean design .