Hi,
I'm learning C, for short my question would be "(how) can I include/tighten functions into structs?".
While learning and looking for this info in other books I couldn't find a way to write "objects with functions" that could be accessed like "myVector.add( param )", instead of "vector_add( &vector, param )".
Here's a snippet:
Code:
#include <stdio.h>
#include "BytesVector.h"
void init( BytesVector *vector ) {
vector->iCurrentIndex = 0;
vector->iCount = 0;
}
//HERE CAN I AVOID PASSING EACH TIME THE POINTER?
void add( BytesVector *vector, char text[] ) {
//do stuff
}
//HERE SAME ISSUE
void setCurrentIndex( BytesVector *vector, int *iIndex ) {
vector->iCurrentIndex = *iIndex;
}
I know in C++ one can write like this:
Code:
void BytesVector::add( char text[] ) {
//do stuff
}
but in C you can't, is that correct..(?)
Bookmarks