C++ :: Dot Operator Versus Arrow

Jun 26, 2014

I understand that the dot operator is:

Code: a.b "a"

is the actual object (not a memory location) and "b" is the member. I also understand the arrow to mean:

Code: a->b "a"

is a pointer to a struct and "b" is it's member so "a" is dereferenced then "b" is given.

Here is where I get a little confused. I have a class:

exampleclass.h
Code:
#ifndef EXAMPLECLASS_H_INCLUDED
#define EXAMPLECLASS_H_INCLUDED
class exampleclass{

[Code].....

Also if ec1 had a public variable and I wanted to access it would it be referenced the same way as the method I call in ec1?

View 4 Replies


ADVERTISEMENT

C :: Double Use Of Arrow Operator With Pointer / Function

Feb 24, 2015

I have recently come across a function call that I do not understand. It uses the arrow operator for a function call, twice, and I don't understand.

Code:

static inline void b43_write32(struct b43_wldev *dev, u16 offset, u32 value)
{
dev->dev->write32(dev->dev, offset, value);
}

I see that the function itself does not return anything but calls another function. The main difficulty I have is with the "dev->dev->" operator, where dev, I expect is a pointer to a structure.

View 8 Replies View Related

C++ :: Merge Sort - Top Down Versus Bottom Up

Apr 28, 2014

I tried to keep the coding style as similar as possible. I tested these with 4 million (4x1024x1024) 64 bit unsigned integers, Visual Studio 2005, 64 bit mode, Win XP X64, Intel 2600K 3.4ghz cpu. The average time for top down = 3.7 seconds, bottom up = 3.5 seconds.

Code: // tsorttd.h - top down merge sort
template <class T>
T * TopDownMergeSort(T a[], T b[], size_t n) {
TopDownMergeSortAtoA(a, b, 0, n);

[Code]....

View 13 Replies View Related

C :: How To Make A Menu That Uses Arrow Keys

Feb 12, 2015

My program uses a menu that easily facilitates a person to navigate trough out it but im stuck on a part and I cant go to menu3 with the arrows (only use c code not c++)

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void sleep(long int interval) {
for(int i=0;i<interval*1000;i++);}

[Code]...

View 6 Replies View Related

C :: How To Create Menu Selection With Arrow Key

Jun 22, 2014

I'm looking for an example of menu selection with arrow key i'dont know how to create one o think i should use CODE ASCI but what method I should follow

View 1 Replies View Related

C++ :: Function Pointers Versus Subclasses

Feb 25, 2013

I am in a position to choose between function pointers and subclassed objects. To make it clear, say I have to notify some object of some action (a timer for example); refer to the following two choices (a very basic code for demo purposes):

Version 1

typedef void TimerCallback(void *args);
class Timer{
public:
Timer();

[Code] .....

Version 2:

class TimerTask{
public:
TimerTask();
virtual ~TimerTask();
void timedout()=0;

[Code] .....

which one is the standard C++ way and which one is efficient?

View 6 Replies View Related

C++ :: Visual Arrow Following Motion Of Ball?

Aug 25, 2013

I have created plane as floor and sphere as ball. I used physics equations to it and ball falls under gravity. Now i want to attach visual arrow to this ball which moves with it according to velocity direction. If ball bounces then direction of velocity is changed so does arrow.

View 1 Replies View Related

C# :: TextBox Navigation Using Arrow Keys

Mar 2, 2014

So I have assigned this method to each TextBox. It works fine pressing the left arrow and right arrow, but for some reason will not work using the up and down arrows. I have tested the string, using MessageBox and it is correct...the loop even proves it finds a matching TextBox. It is correct as in it displays the TextBox name it should be selecting but doesn't. I have no clue! Now the first select method is the one I want to use, I used the loop to check to see if it was even finding a match. It does find it but doesn't select it. The naming convention for my text boxes is r1c1 where the first number indicates the row and the second number is the column. There are 9 rows and 9 columns. This SHOULD be working but for whatever reason it is not. I've even put a message box inside the if statement for the up and down keypress check and it pops up when i press up or down.

private void Navigate(object sender, KeyEventArgs e) {
TextBox input = (TextBox)sender;
string nextBox = input.Name.ToString();
if (e.KeyCode == Keys.Left) {
if (int.Parse(nextBox.Substring(1, 1)) > 1 && int.Parse(nextBox.Substring(3, 1)) == 1)

[Code] ....

View 7 Replies View Related

C Sharp :: How To Detect Whenever Down Arrow Key Is Pressed

Jun 3, 2012

So, I've been working on a project recently, and the only thing remaining to do is a detector to whenever down arrow key is pressed. The down arrow key can only trigger when a certain check box is checked and this will have to work with a timer either. The problem is that how to make the down arrow key press detector(I've got the check box and timer ready tho).

View 10 Replies View Related

C++ :: Detect Arrow Key Press For Linux Only

May 13, 2012

I'm trying to implement this on ubuntu, to compile and run only under ubuntu.

I found 100s of other attempts at answering the general question of arrow key press in c++. Nothing solid.

Some recommend using the Readline for the functionality I am trying to implement, but I need to stay clear of GNU licences if I can for this project. And some tips only work on projects for windows machines... for example the conio library.

For linux there may be the option of using the ncurses library which I will take a look at, but I am stubborn and want to implement this myself. It should be an easy straight forward thing to do, which is why I am a bit frustrated at the moment.

Here is my test code so far.

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;

[Code] ....

So! This works... 80% of the problem is solved. If you compile this, g++ under linux, ubuntu in my case, and run. Each keystroke reveals the correct key numbers.

q=113
w=119

when I click on the up key I get,

up = 279165

I thought, I can use this number is a if(int == '279165') to detect the up key.

I was not so lucky... this int is not behaving like an int!

So I modified the code to see it I could carry out an int operation on this number.

I added a 100000 to int i.

cout<< i + 100000;

Code:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;

[Code] .....

Compiling and running this, and pressing the UP key gives the following number.

100027100091100065

Some some sort of array, something like, [27][91][65].

I tried all ways to access these individual numbers, actually the third one for comparison purposes, but no luck.

For completeness sake I list the other arrows.

UP = [27][91][65]
DOWN = [27][91][66]
LEFT = [27][91][68]
RIGHT = [27][91][67]

A little further digging shows that these numbers are derived from the representation of a "multi-char" constant, the data type given when pressing special characters...

Now here is the main problem I have, I can find ANY decent documentation on how to handle and play with "multi-char" .

View 4 Replies View Related

C++ :: Static Versus Dynamic Array

Feb 27, 2013

there is a performance difference (e.g access time, speed, ...) between allocating static memory vs dynamic memory?

For example, if am reading data from a file, and storing them inside a huge buffer, what would be the differences between storing these data inside a static buffer vs a dynamic one?

View 3 Replies View Related

C++ :: Runtime Speed Integer Versus Double

May 27, 2013

Using integers faster than using floating points? Or more precise: what do you estimate as the chance that writing a custom floating point class is worth the effort?

I need to examine some C++ code for an ARM7 or ARM9 processor. Instead of using floating points, the coder had chosen to use integers only. To be able to fake floating points, a custom class was written. The coder states that he avoids using floating points as these are much how much slower. "Have you measured this?", I asked. "No, but it is known to be so", he replied.

Google taught me that most people state integers are faster than using doubles, because their operations (addition, multiplication) take less assembler instructions. But if you need those floating points, what do you estimate as the chance that writing a custom floating point class is worth the effort?

View 2 Replies View Related

C++ :: Array Char Rotation And Arrow Key Usage

Apr 27, 2013

I am doing a project for a class which involves making a game where there is an arrray that holds a player (you) and a zombie (comp). The player is suppose to be able to turn clockwise or counter clockwise, move forward, and backward and shoot. Im having trouble trying to rotate the char in an array. I am also trying to switch from using the W,S,D,A to the arrow keys but doesnt seem to work.

#include <iostream>
#include <windows.h>
#include "color.h"
using namespace std;
using namespace Petter;
const int COL = 15;
void initBoard(char[][COL], int, int);

[Code] ....

View 5 Replies View Related

C++ :: Array Versus Linked List Implementation For Stack

Nov 27, 2014

Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?

View 1 Replies View Related

C++ :: Print In Asterisks Oval / Arrow And Diamond Using For Loop And If Statements

Jan 15, 2015

#include <iostream>
using namespace std;
int main(){
return 0;
}

this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.

View 1 Replies View Related

C/C++ :: Doubly Linked List Versus Double Ended Queue

Jun 27, 2014

A while ago i was asked to write a program for a class that used a "Double ended queue with a current-position marker."

An example of some of the functions that i created are:

boolean atFirst() // Returns true if first element is current. Pre: !isEmpty().
boolean atLast() // Returns true if last element is current. Pre: !isEmpty().
void makeEmpty() // Sets this List to the empty state. Post: isEmpty().
void moveFirst() // Sets current marker to first element.
void movePrev() // Moves current marker one step toward first element.
void moveNext() // Moves current marker one step toward last element.
void insertBeforeFirst(int data) // Inserts new element before first element.

My question is whether a double ended queue with pointer is the same thing as a "doubly linked list" in this case. The terminology is throwing me of a little. If the two concepts are different, how is a doubly linked list different?

View 2 Replies View Related

C++ :: Calculate Percentage Of Times Coin Flipped Either Heads Versus Tails

Feb 10, 2015

I'm having trouble getting the program to calculate the percentage of times it flipped either heads versus tails. I realize what I currently have doesn't work because above I initialized heads and tails by giving them values of 0, but I'm unsure of how to fix it.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main () {
srand(time(0));

[Code] .....

View 2 Replies View Related

C++ :: Namespaces / Classes - Perform Operator Overload With Insertion Operator

Mar 22, 2013

I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.

Here's my class [In a header file "Shinigami.h"]

#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);

[Code] .....

If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.

I thought it was the namespace, but I included that.

View 9 Replies View Related

C++ :: Implementation File Versus Header File - Eclipse Giving Errors

Feb 10, 2013

I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?

#include "KeyValuePair.h"
template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()

[Code] .....

View 3 Replies View Related

C++ :: Reading In Space Separated Versus Comma Separated Files

Jul 30, 2014

I just wrote a code that reads in a text file called "policies.txt" which looks like this:

Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99

This works perfectly fine, but what if I want each element of the table to be separated by commas. For example:

Pol1,M,N,20,100000,1,.04,99
Pol2,F,S,30,100000,1,.05,99
Pol3,M,S,72,750000,1,.03,99
Pol4,F,N,45,1000000,1,.05,99

or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work? This is my code to reference.

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};
double ratesms[86] = {
#include "MaleSmoker.txt"

[Code] ....

View 4 Replies View Related

C :: How To Use Conditional Operator

Jan 25, 2013

i know

Code: (condition) ? true-clause : false-clause

but how do you use an array as the condition, how will the code look?For example i want to write

Code:

string numbers[5] = {"one","two","three","four","five"};
numbers == "one" ? thumb : again; thumb and again will replace something else. Don't worry about them.

how do i say that if the numbers array is representing "one" then it replaces as "thumb", otherwise "again".

View 5 Replies View Related

C++ :: Class Using New Operator

Jan 5, 2015

Is it usual to rely completly on the new operator in constructors/copy constructors. What if new trows an exception? The application ends and that's it? The new operator can be placed where it can't be catch like in constructor initialization list. What kind of practice I should adopt when using "new" in those cases?

The sample code below is taken from here... [URL] ....

class MemoryBlock {
public:

// Simple constructor that initializes the resource.
explicit MemoryBlock(size_t length)
: _length(length)
, _data(new int[length])

[Code] .....

View 9 Replies View Related

C++ :: Overloading I/O Operator

Oct 26, 2013

In this below example:

class Point {
private:
double m_dX, m_dY, m_dZ;

[code].....

In that situation, << does not call the overloaded function, but rather calls the << method defined in the i/o library, which prints a message to the controlling terminal. So once it prints the message to the terminal, it then returns the out instance. Why return the out instance rather than a boolean like true? As you can see from the example, once the message is printed to terminal, out is not used anymore.

View 2 Replies View Related

C++ :: How To Overload Operator Twice

Jul 10, 2014

Here's my question. I'm coding a basic Linked List class (for the purpose of understanding and having fun, I know about STL), LList.

I have overloaded the [] operator so it returns the data of the index-th node in the list, for example, if I code

LList x;
....
cout<<x[5];

it prints the data of the 5th node in the list (for fun I decided to index from 1 to infinity).

My question: Now I want to be able to assign the value to the index-th node data, using [] and =, for example, I want to be able to write:

LList x;
.....
x[5] = 121;

How can I do that?

View 3 Replies View Related

C++ :: WAP Using Ternary Operator

Aug 13, 2014

1.WAP in C++ to enter marks in 3 subject and calculate percentage and grade.cond given below (Using Ternary operator)

Per Grade
90-100 A
80-90 B
70-80 C
0-70 D

2. WAP to enter 3 no.s in and print them in ascending and descending order .(Using Ternary operator)

View 8 Replies View Related

C++ :: STL Map Compare Operator

Jun 13, 2012

In stl map, if I insert two keys, say a and b. It looks like compare operator is called twice. First time a<b is called and second time b<a is called. Why are both a<b and b<a called?

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved