C++ :: How To Change 2 Dynamic Array Int Vector Class
Oct 29, 2014
// dynamic memory for 2D char array
char **board = (char**) calloc(column, sizeof(char*));
for(int i=0; i<column; i++)
board[i] = (char*) calloc(row, sizeof(char));
//for char 255 row and colum
char temp[255];
inputFile.getline(temp,255);
[Code]...
so i want to change into vector class like Vector<board>row;
View 8 Replies
ADVERTISEMENT
Sep 13, 2013
So this is the code I have so far, I didn't know it had to be a dynamic array so how would I Utilize dynamic array allocation to size the modal array
#include <iostream>
using namespace std;
int main() {
const int arraySize = 25;
const int patternSize = 10;
[Code] ....
View 1 Replies
View Related
Apr 3, 2013
How do I copy from a dynamic array initialized in a class but with a different memory address. For example if my array is a dynamic array initialized in a class...
Code:
const int CAPACITY=5;
class Array{
public:
Array();//constructor
[Code] .....
How would i copy this array to a another array but have a different memory address so when i deallocate array a my copy array also isn't deallocated.
View 1 Replies
View Related
Nov 14, 2013
I'm writing a class that has two constructors. However, I can't get them to work quite right. One constructor has a parameter of an int (with a default value of 0) and the other has a parameter of a C-style string.
First of all, are these function prototypes correct for the constructors?
MyInt(int n = 0);// first constructor, int param, default value 0
MyInt(const char * c);// second constructor, c-style string param
Both constructors work fine in some cases but don't work in all cases. Here are some potential calls to these functions that are supposed to work:
// These two work fine
MyInt x(12345),
y("9876543210123456789"),
// The array assignment doesn't work when the value is negative
// I'm not allowing negative numbers, but I want to create the object and assign the array to 0
r1(-1000),
[Code] .....
Here's the private data from the class (from the header file):
private:
int currentSize,
maxSize;
char* digits;// Pointer to an array of digits
// Increase the size of digits array by 5
void Grow ();
View 2 Replies
View Related
May 10, 2014
I attempted to create a dynamic array class for use in my engine (due to problems regarding a dll-interface with the standard library), so I tried at making a standard-compatible allocator template class first. After I "finished" that, I went on to work on the dynamic array class itself.So I finish the dynamic array class, and test it with the standard allocator. It works perfectly, but when I test it with my custom allocator class, it fails terribly.
To make sure it wasn't my DynamicArray class that was causing issues, I tried using the custom allocator on the std::vector class template, and it didn't work either. IMy DynamicArray class code:
// Represents a dynamic array, similar to the standard library's "vector" class.
template<typename T, typename A>
class DynamicArray
{
public:
DynamicArray() :
data(nullptr),
elements(0),
capacity(0)
[code].....
The "Request" and "Free" functions are my engine's equivalent of malloc and free (or new and delete). I allocate a large buffer (16 mb), and through those functions I distribute the memory to where it's needed.
View 9 Replies
View Related
Nov 29, 2014
I have a class called Book and I am trying to create a dynamic pointer based array of the class. When I try to run the program I keep getting the error: pointer being freed was not allocated at the line of code that says "delete [] A;". I am using Xcode to run the program.
Book *changeArraySize(Book *A, int &size, double factor) {
int i;
int newsize = size*factor;
Book *A2 = new Book[newsize];
[Code] ....
View 7 Replies
View Related
Apr 11, 2012
I use ffmpeg codes in my C++ app and would like to control the bit_rate parameter for VIDEO there. I tried to change its value in work (via ost->st->codec->bit_rate = 150000), but ffmpeg did not wish to change it.
I tried to make re-init of the codec:
Code:
....
ost->st->codec->bit_rate = 150000;
AVCodecContext* newContext = avcodec_alloc_context3(ost->enc);
avcodec_copy_context(newContext, ost->st->codec);
avcodec_close(ost->st->codec);
av_free(ost->st->codec);
ost->st->codec = newContext;
avcodec_open2(ost->st->codec, ost->enc, &ost->opts);
the program hanged after that codes.
View 2 Replies
View Related
Jan 4, 2013
I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.
unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{
[Code].....
View 2 Replies
View Related
May 3, 2014
What I am trying to do is read a sequence of words from cin and store the values on a vector. Then process the vector and change each word to uppercase.
I know line 21 is the problem. I think I don't have the right syntax. That syntax works on string. I'm trying to adapt and use it on vector but it doesn't work.
#include <iostream>
#include <string>
#include <vector>
int main()
[Code]....
View 7 Replies
View Related
Apr 22, 2014
I am trying to change the value of of time in my vector of structs. The result should output 1430 as the value of shares[1].time though I get something different.
unsigned convTime = 1430;
std::stringstream out;
out << convTime;
shares[1].time = out.str();
std::cout << shares[1].time;
But my shares[1].time stays as its original value and not 1430.
View 1 Replies
View Related
May 13, 2013
I need to create a class vector as a template and define operations on vectors.
And this is what I made.
#include<iostream>
using namespace std;
template<class T>
[Code].....
View 2 Replies
View Related
Sep 4, 2013
I just wondering if there's a way in C++ to get classes dynamically which have the same base class? I mean, instead of creating switch statement to create multiple classes, I would like to use a single line to create any of these classes.
//Instead of:
switch(class_type) {
case type_1:
SubClass_1 obj = new SubClass_1();
[code].....
View 4 Replies
View Related
May 6, 2014
I'm trying to change the values of some instance variables in my Controller Class so that when the user inserts values into main class it changes for Controller.
class Controller {
public:
Controller();
~Controller();
double PCFreq;
__int64 CounterStart;
[Code] ....
The user should be able to choose which foo the want to use. So I create an object of controller in main like this
Controller* con = new Controller()
Now my issues is, when I take user input (an integer) and try to do this
con->choice1 = choice1;
only the object of con's choice1 is = to user input.
However back at the class for Controller, choice1 hasn't received a value.
I can't initialize through Controllers constructor because I get the user input through a switch statement and the range of con would only be as far as the case.
View 2 Replies
View Related
Apr 17, 2014
I'm having problems with this code:
#include <iostream>
using namespace std;
class Foo {
public:
Foo( int n );// Constructor
~Foo();// Destructor
int *ptr;
int N;
[Code] ....
I'm using Visual C++ 2008 version. The problem arises at the end, after the sentence 'system("pause")' is reached, which makes me think that the problem happens when calling the destructor. The destructor is called twice, the first time it's called is in the function print. The problem seems to be that the destructor can only be called once.
I know I can avoid this situation by defining the function print like this:
void print ( const Foo &f )
...
but I would like to know if there is some way I can do this keeping the definition that I've provided.
View 2 Replies
View Related
Apr 25, 2014
Class with Pointers and Dynamic Arrays
View 2 Replies
View Related
Mar 27, 2014
I have become overwhelmed an frustrated at these current operator overloads!
Currently I still can not get my +,* or istream operators working at all!
#include <iostream>
#include <cstring>
#include "myint.h"
[Code]....
View 1 Replies
View Related
Feb 6, 2012
I want to allocate dynamically classes from a table. There is a different number of class derived from the same father class. Actually I do:
Code:
typedef struct sSysFBList {
TCHAR name[64];
int dim;
SystemFB *fbExec;
}systemFBCalls;
[Code] ....
and so on. NOTE: SystemFB is the virtual father class, all the other are derived from it.
I would like to know if there is the possibility to define the type of the class in the systemFBCalls struct to avoid all these if - else if - else if
Code:
typedef struct sSysFBList {
TCHAR name[64];
int dim;
????? name_of_class;
SystemFB *fbExec;
[Code] .....
View 4 Replies
View Related
Jun 1, 2012
I have base class with some properties(variables).I want to inherit that class and want to change name of that properties in the derived class using concept of Shadowing.
View 1 Replies
View Related
Feb 9, 2015
How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.
here is my code:
#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)
[Code].....
View 3 Replies
View Related
Jul 8, 2012
is there a way to have a template class respond to missing stuff in a template type ?
Code:
template <typename Type>
class MyClass
{
public:
enum { ID = Type::ID }; // revert to 1 if Type::ID doesn't exist.
};
If the Type passed to the template has an ID member (required to be an enum or a static const int), use it, if it is missing revert to a default value.
I can use this as a simplified way of configuring how MyClass works, without requiring Type to explicitely needing to define what it doesn't care about.
It needs to be resolved at compiletime, as it determines the number of elements in member array variables.
View 10 Replies
View Related
Dec 14, 2014
im passing a vector of a class to a function of another class. But i cant access the data on the classes inside the vector.
Something like that:
class CDummy{
...
public:
string m_name;
[Code].....
Im creating the vector on main() and using push_back with a pointer to an initialized CDummy instance
View 5 Replies
View Related
Oct 15, 2013
How I can implement it.
Tickable.h
#include <list>
#ifdef TICKABLE_EXPORTS //Automatically defined by MSVS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#pragma comment(lib, "Tickable.lib")
#endif
class DLL Tickable{
[Code] ....
error LNK2001:
unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST
PATHTickable.obj
I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.
Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?
I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.
View 5 Replies
View Related
Mar 13, 2013
But it can the other way around
Code:
static_Array= dynamic_Array;
dynamic_Array = static_Array;
The second statement works and i'm able to print out both arrays with equal values but with the first
[code] static_Array = dynamic_Array;I get incompatible types in assignment of 'int*' to 'int [7]' is the error I get [/code]
View 2 Replies
View Related
Apr 17, 2014
use 2D array in function and change the array values. I do not know if I can use array by calling from a function. I have 6 row 6 column array, I used it inside a function and for the another function I just need to change 4. row 4. column and I do not want to type array to just change one part. I do not know if there is another way or not
View 7 Replies
View Related
Oct 1, 2013
I want to pass an array to a function and change the array, how can I do that?
Code:
#include<stdio.h>
/*function to change the array*/
void rearng(int *qw) {
int i,j,a;
int sa[8]; //temp array
int c = 0;
int high;
[Code] ....
View 6 Replies
View Related
Feb 20, 2013
My coin/money change code works when there can be an exact change each time, i.e. when the 1 cent option is available. However, when the change options are only $10, $5, $1, 25 cents and 10 cents, it does not give me what I want for instance, I wanted to get change for $237.80, I was expecting to get:
23 10's, one 5, two 1's and 8 dimes. However, the code below is giving me 23 10's, one 5, two 1's and 3 quarters (there is no option left for the 5 remaining cents).how to fix it?
Code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void change(double cents, int a[]);
int main() {
double Dollars;
double cents;
[code]...
View 14 Replies
View Related