Ok, so I'm tyring to iterate through an ArrayList and remove a specefic element. However, I am having some trouble using the For-Each like structure. When I run the following code:
ArrayList<String> arr = new ArrayList<String>();
//... fill with some values (doesn't really matter)
for(String t : arr)
{
t = " some other value "; //hop...
This is a follow up on this question: Display previously received UART values.
After implementing a circular buffer on the microcontroller, it seems that there is a problem with the pointers.
Sent on RS-232: ADE1234
Received (buffer = 8): E24AE2 / E2AE24 (Flips between the two)
Received (buffer = 16): D234E1 (A is skipped, since it i...
I have created a function to flip a square 2d array horizontally, so the first row is moved to the last, the second row is moved to the second from the last and so on.
Here is the function:
void flipMatrix(int size, int matrix[ROWS][COLS]) {
int row, col;
int temp[ROWS][COLS];
for (row=0; row < size; row++) {
for (...
Hi, could anyone explain (by giving appropiate link for example) what does pointer alignment in c++ means?
Thank you.
...
#include <stdio.h>
#include <stdlib.h>
void
getstr(char *&retstr)
{
char *tmp = (char *)malloc(25);
strcpy(tmp, "hello,world");
retstr = tmp;
}
int
main(void)
{
char *retstr;
getstr(retstr);
printf("%s\n", retstr);
return 0;
}
gcc would not compile this file,but after adding #include <cstring> I could use g++ to compile this...
How can one swap pointer addresses within a function with a signature?
Let's say:
int weight, height;
void swap(int* a, int* b);
So after going out of this function the addresses of the actual parameters (weight and height) would be changed. Is it possible at all?
...
Hello,
I notice this has caused confusion for several people, but after reading a couple of posts on here and the cplusplus tutorial my brain is still scrambled.
Suppose I have the following variables in a header file -
int numberOfLinePoints;
D3DXVECTOR3* line; //confused as to what it is
Then in the implementation C++ file I ini...
hi!
I would like to pass a pointer by reference to a function, such that i can actually change the address the passed pointer is pointing to and i'd like to assign this argument a default value.
something like this:
in the declaration
void myFunc(SomeType* &var=NULL);
and the definition:
void MyClass::myFunc(SomeType* &var){
i...
How do I do the following declaration?
int main(int argc, char *argv[]) {
char *users[] = {};
char *names[] = {};
openPasswd(users, names);
return 0;
}
void openPasswd(char &users[] = {}, char &names[] = {}){
}
I want to populate the 2 char arrays from the function back to the main program.
How do I do this?
...
Here's my problem: I have an object that's referencing a DLL. I would like other objects to reference my object, without having to also include a reference to the DLL itself.
This is fine for the most part except there is an enum in the DLL that I would like to replicate. I could write out the enum line by line, but I'm wondering if the...
For the C code below, compare the defintions of the int pointers a and b;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *a=malloc(sizeof(int));
int *b=(int *)malloc(sizeof(int));
return(0);
}
Is it better in any way to typecast the pointer of type void, returned by the malloc function?
Or is it auto-typecasted while...
I was helping a friend with some C++ homework. I warned said friend that the kind of programming I do (PHP, Perl, Python) is pretty different from C++, and there were no guarantees I wouldn't tell horrible lies.
I was able to answer his questions, but not without stumbling over my own dynamic background. While I was reacquainting myse...
Take a look at the following code:
var o;
(function (p) {
p = function () {
alert('test');
};
})(o);
o(); // Error: 'o is not a function'
In the above function I am creating an anonymous function that takes one parameter, which self-invokes with a previously-created object passed as a parameter.
Then I am pointing th...
Hello,
i have small problem understanding why my smart pointer class is leaking on self assing.
If i do something like this
SmartPtr sp1(new CSine());//CSine is a class that implements IFunction iterface
sp1=sp1;
my colleagues told me that my smart pointer leaks. I added some log messages in my smart pointer to track what is going on ...
I keep getting this error -
error C2819: type 'List' does not have
an overloaded member 'operator ->'
i can't figure out why? help?
Main.cpp -
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
#include "List.h"
#include "Node.h"
The error happens here:
void PrintList ( List list ) {
Node * tem...
Hello all,
I am working on implementing a function that would execute another function a few seconds in the future, depending upon the user's input. I have a priority queue of a class (which I am calling TimedEvent) that contains a function pointer to the action I want it to execute at the end of the interval. Say for instance that th...
Does it ever make sense to check if this is null?
Say I have a class with a method; inside that method, I check this == NULL, and if it is, return an error code.
If this is null, then that means the object is deleted. Is the method even able to return anything?
Update: I forgot to mention that the method can be called from multiple th...
Hi!
I'm making a game engine in C++. It is supposed to read all its game-level logic from XML files, so I'm in need of a simple, but rock solid way of creating and handling events. So far all i have done is to use an Action class. It's practically equivalent to throwing callbacks around.
An example could be an object (a map), that can ch...
I am wondering why a structure pointer seems to be behave differently than a char pointer.
typedef struct person_struct {
char *name;
} person;
changeStructName(person * name1)
{
name1->name = "Robert";
}
changeCharName(char * name2)
{
name2 = "Jose";
}
int main()
{
person * name1;
...
char byte_to_ascii(char value_to_convert, volatile char *converted_value) {
if (value_to_convert < 10) {
return (value_to_convert + 48);
} else {
char a = value_to_convert / 10;
double x = fmod((double)value_to_convert, 10.0);
char b = (char)x;
a = a + 48;
b = b + 48;
*converted_value = a;
*(converted_value+1) = b;
r...