decalration won't allocate storage, while definition will. This is a test program:
#include <iostream>
using namespace std;
extern int ei;
int i;
[Code].....
Others are all fine in this program except ei.
compiler error: undefined reference to ei.
I understand ei is only declared so there is no memory address, but when I do ei=1, then ei completed it's definition, why still cannot use pei to get it's address?
I have a class that I'm going to use to store a category. Right now there are seven options, but there is the potential for a whole lot more in the future. So I started off by storing an integer as the private member. I then used static constants to define the numeric values to represent each category, then a set of static constant strings that corresponds to those numbers in case I need their actual names. Finally I set up some static functions to convert between the integer value and the string, and vice versa.
I'm not sure if this is the best way to go about this. For one it makes the categories names and designations unchangeable. I thought that storing them in a file would be a better option, but then i needed a container that is the equivalent of a constant.
I thought of defining a class to contain an int and the associated string. It would be designed so that it can only be initialized with both items. Then provide no functionality to change the contents. So I've basically created my own constant.
I made a program and when I try to use the main driver to instantiate everything it says invalid storage class for a function. All of my code is in 4 separate files i'm just trying to get it to run now.
I am porting code from windows using visual studio to mac with xcode.
Quite a lot of issue have a appeared, which is no surprise, one warning that keeps on appearing is Explicit Specialiszation cannot have a storage class:
So the RPG I have been making is based on this tutorial URL.....I don't entirely understand how the Item storage system is supposed to work. It looks like the array shown is for one item but, there are 3 lines of code that correlate. The author says that this is a repeatable bit of code for each item so.... i'm just completely lost. The player will have two or three to start and there are 4 battle/health items and one key ....
where to start and how it should be structured. how I should go about writing this program, like should i make functions, pointers, etc. And to display the menu, is it easiest to just use printf statements or is there something more efficient.
# include <stdio.h> # include <math.h> # include <stdlib.h> # include <malloc.h> }
[code]...
I am compiling it on a 64 BIT ubuntu machine having 64GB ram using gcc 4.6 compiler. I am getting the following output Error allocating memory. But (914*866*2724) is approximately 8 GB, Whats wrong with the code?
I am allocating space only for two characters but it fits all of them, if you run this it will print the whole string literal "hello my friend". How is that possible?
I am using gcc 4.6.3., I know about strncpy().
#include<iostream> #include<cstring> using namespace std; int main(){ char* str = new char[2]; strcpy(str, "hello my friend"); cout << str << endl; return 0; }
I wrote the following C++ constructor, and I get an error - BUFFER too small on strcpy_s
Trace::Trace(const char *str) { if (str) { int len = strlen(str); this->m_name = new char[len+1]; // asking for 'len+1' memory elements of char strcpy_s(m_name, len, str); // **** I get here an error "BUFFER TOO SMALL" ****
Working on this one from the Jumping into c++ book. The book asks that I create a multidimensional array at run time based on user input and fill it with a multiplication table
My code compiles fine but throws an uninitiated error for p when I try and run it.
Code: void multiDimentionalMultiplication(int x, int y, int z){ int ***p; **p = new int[x]; std::cout << "Allocating array.
This is what I'd expect, but I can't find any evidence online in C standards or elsewhere:
1. Works as expected, sets the value of a.num1 to 2. 2. Works as expected, sets the value of b.num1 to 2. 3. Works as expected, sets the value of a.num2 to 2. 4. Works as expected, sets the value of b.num2 to 2. 5. Works as expected, sets the value of b.num1 to 2. 6. Works as expected, sets the value of a.num1 to 2. 7. Works as expected, sets the value of b.num1 to 2. 8. Crashes/Memory Corruption, attempted to alter memory outside struct. 9. Works as expected, * ss1 == * ss2 10. Crashes/Memory Corruption, attempted to alter memory outside struct.
I've tested simular code on my machine (Xubuntu 14.04LTS compiled with gcc on -O3) and it appears to be reliable, given that you stick with acessing the type tagged in the struct or the common initial union struct members (in this case num1).
I am trying to figure out the syntax to dynamically allocate a single dimension of a triple dimensional array. Basically i have a 2D array of structs. but each struct is an array (basically rows of the information). The rows of this structure need to be allocated dynamically, but the height and width of the overarching structure are static.
Basically: Struct * ts_FieldInfo[100][100] = new Struct[Class.returndataitems()];
so I have this code that dynamically allocates a pointer array increasing and removing elements of the array as its operated on.then it sorts and prints out the array when the user is finished operation on the array. i get this error message when running the program though.
"Unhandled exception at 0x0F474F98 (msvcr110d.dll) in Lab10_VarArray.exe: 0xC0000005: Access violation reading location 0xCCCCCCC0."
this is my code
#include <iostream> #include <cstdlib> #include "Header.h" using std::cout; using std::endl; using std::cin; int main(void) { char op='x';
I'm making some multi-threaded program, but thats not my problem as i've done that already. I have a class with user-functions containing a structure which then contains a two dimensional array for each user with 25 elements. So I dont want to limit the user and make the array for example with just 10 rows, but allocate the needed memory to match the amount of 'users' a potential user of my program would want. The problem is, that i know how i should allocate it using 'new int' but it just doesnt work ! It gives an error:
Then, in some completely other class function inside the file mentioned above: (I know i could do a function in CUsers class which could allocate the memory, but I have this function which is used for some other things and it already has the amount of max users
void OtherClass::somefunction(maxusers) { // This gives an error: Error: no operator "=" matches these operands curUsers->uData.userNumbers = new int*[maxusers]; //maxusers is the int variable of max users specified by the client // However this doesn't for( int i = 0 ; i < maxusers ; i++ ) curUsers->uData.userNumbers[i] = new int[25]; // 25 columns, this doesnt give any error }
I'm not really sure what I'm doing wrong. Doing this in some function from CUsers class works (without curUsers-> or with, doesn't give any error) but doing it from some other class's function doesnt.
I want to be able to dynamically allocate and index an array like the following: vv2d[1][2].x and vv2d[1][2].y. In order to accomplish that I have chosen to use a std::vector of a std::vector of a 2D point class.
Code: /// Here is my templated version of a 2d point class which I have adopted from /// one by Alexander Chernosvitov, Function Graphics, 2001 (see ogview.h) /// http://www.codeguru.com/cpp/g-m/opengl/article.php/c5581/Function-graphics-in-3D.htm template <typename T>
[Code]....
Boundary violation occurs as soon as vv2d[1][0].x is encountered. I believe the problem is my inability to dynamically allocate the size of the (primary) typedef vector. However, eliminating the typedef for the following does not change the result. Further examination shows the vv2d[1][0] size and capacity to be 0.
This is a homework assignment where I have to read a file into a dynamically allocated 2d array. The file format is 10 Jim 3.6 Jake 4.0 Will 3.0 Sara 3.4 Mike 2.5 Ellen 2.9 Melissa 3.9 Eric 3.8 John 3.5 Beth 3.9
where 10 is the number of students followed by the students and the gpa's. There is more to the program but I have not implemented it yet because I am getting a segmentation fault. The output I am getting when I print the array is Jim 3.6 Jake 4.0 Will 3.0 Sara 3.4 Segmentation fault
I can see where the problem lies. If I raise value for row when I am allocating the rows of the array, all of the names print. I just do not see why I need to. From my understanding the row * sizeof(char*) should give me enough room for 10 entrie.
Code: #include <stdio.h> #include <stdlib.h> void sort(); int main()