I have a class, "Tetris", in which one of the instance variables is "board". "board" is 2D array of Color objects. Upon the creation of a tetris object I call a method that sets the dimensions of board and then sets all of the Color objects to be the Default value, that is to say, Color.blue.
public Tetris(int rows, int cols) {
this.r...
I have a problem with a template and pointers ( I think ). Below is the part of my code:
/* ItemCollection.h */
#ifndef ITEMCOLLECTION_H
#define ITEMCOLLECTION_H
#include <cstddef>
using namespace std;
template <class T> class ItemCollection
{
public:
// constructor
//destructor
void insertItem( const ...
If Java does not have pointers then what does the the new keyword do in Java?
I am confused, please explain.
...
I've searched but couldn't find any results (my terminology may be off) so forgive me if this has been asked before.
I was wondering if there is an easy way to call a void* as a function in C without first declaring a function pointer and then assigning the function pointer the address;
ie. assuming the function to be called is type vo...
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 ...
I have a program in C using Solaris with VERY ancient compatibility it seems. Many examples, even here on SO, don't work, as well as lots of code I've written on Mac OS X.
So when using very strict C, what is the safest way to pass strings?
I'm currently using char pointers all over the place, due to what I thought was simplicity. So...
I have a small assignment in C. I am trying to create an array of pointers to a structure. My question is how can I initialize each pointer to NULL? Also, after I allocate memory for a member of the array, I can not assign values to the structure to which the array element points.
#include <stdio.h>
#include <stdlib.h>
typedef str...
Why is the following code resulting in Segmentation fault? (I'm trying to create two matrices of the same size, one with static and the other with dynamic allocation)
#include <stdio.h>
#include <stdlib.h>
//Segmentation fault!
int main(){
#define X 5000
#define Y 6000
int i;
int a[X][Y];
int** b = (int**) malloc(...
I'll cut a really long story short and give an example of my problem.
Given a class that has a pointer to a primitive type as a property:
@interface ClassOne : NSObject
{
int* aNumber
}
@property int* aNumber;
The class is instantiated, and aNumber is allocated and assigned a value, accordingly:
ClassOne* bob = [[ClassOne alloc] in...
Below, I wrote a primitive singly linked list in C. Function "addEditNode" MUST receive a pointer by value, which, I am guessing, means we can edit the data of the pointer but can not point it to something else. If I allocate memory using malloc in "addEditNode", when the function returns, can I see the contents of first->next ? Second ...
hi,
i am very new to c++. i am getting system crash (not compilation error) in doing following:
i am declaring global pointer of class.
BGiftConfigFile *bgiftConfig;
class BGiftConfigFile : public EftBarclaysGiftConfig { }
in this class i am reading tags from xml file. it is crashing system when this pointer is used to retrieve va...
i have the memory address of certain register(the address LCDCW1 is C000).
c codes:
#define LCDCW1 0xC000
*LCDCW1=0x31;
i just want to write data to this register. The codes have problems, how to correct it?
thx!
...
EDIT: I know in this case, if it were an actual class i would be better off not putting the string on the heap. However, this is just a sample code to make sure i understand the theory. The actual code is going to be a red black tree, with all the nodes stored on the heap.
I want to make sure i have these basic ideas correct before mov...
I have a parent class which is templated, and a child class which implements it.
template< typename T1, typename T2>
class ParentClass{ . . . };
class ChildClass : public ParentClass<MyT1, MyT2> { . . . };
And I want to have a pointer which I can use polymorphically:
ParentClass<T1, T2>* ptr;
ptr = static_cast<ParentClass<MyT1, MyT2>...
Hi All
I am working on representation of the chess board, and I am planning to store it in 32 bytes array, where each byte will be used to store two pieces. (That way only 4 bits are needed per piece)
Doing it in that way, results in a overhead for accessing particular index of the board.
Do you think that, this code can be optimised o...
It may be a bit confusing, but...
Let's say I have a vector type member in a class, something like vector<Operator*> ( I have methods on my class to return Operators from this container).
Now lets say that I have a method on my class that receives an Operator object op and inserts it on the vector. What I want to know is: will I have an...
Let's say I have this:
SolutionSet(const SolutionSet &solutionSet) {
this->capacity_ = solutionSet.capacity_;
this->solutionsList_ = solutionSet.solutionsList_; // <--
}
And solutionsList_ is a vector<SomeType*> vect*. What is the correct way to copy that vector (I suppose that way I'm not doing it right..)?
...
Hello, I'm having some trouble to find the best way to accomplish what I have in mind due to my inexperience. I have a class where I need to a vector of objects. So my first question will be:
is there any problem having this: vector< AnyType > container* and then on the constructor initialize it with new (and deleting it on the destruc...
On this page, it's written that
One reason is that the operand of
delete need not be an lvalue.
Consider:
delete p+1;
delete f(x);
Here, the
implementation of delete does not have
a pointer to which it can assign zero.
Adding a number to a pointer shifts it forward in memory by those many number of sizeof(*p) units...
I just started learning C++ (coming from Java) and am having some serious problems with doing anything :P Currently, i am attempting to make a linked list, but must be doing something stupid cause i keep getting "void value not ignored as it ought to be" compile errors (i have it marked where it is throwing it bellow). If anyone could he...