C++ :: Two Identical Storage Containers - Typecasting

Oct 27, 2012

I have a situation where I have two identical storage containers:

Code:
////////////// multiplatform version
union _SOVector3 {
struct { float x, y, z; };
struct { float r, g, b; };
float v[3];

[Code] .....

SOVector3 is part of a namespace with specialized functions that are generic and intended for multiplatform usage.

GLKVector3 is dedicated to the Mac and has its own set of functions.

But what I want to do is freely interchange the storage between these two namespaces. Such as like this:

Code:
start = clock();
SOVector4 myVec4 = SOVector4Make(1.0f, 3.0, 6.0f, 1.0);
SOMatrix4 myMat4 = SOMatrix4Identity;
for (uint i=0; i<100000; ++i ) {

[Code] ....

But I am getting errors when I typecast this.

View 1 Replies


ADVERTISEMENT

C :: How To Output A Char Array And Typecasting

Jan 1, 2014

Code:
#include main() { char why[64]; why =255,255,255,255,255,255,255,255;
while (why > 4); printf("why is equal to" ,why); why = why-2;
return 0;
}

It tells me incompatible data type.

View 9 Replies View Related

C++ :: Typecasting Char Array To Int (Not Converting)

Jun 1, 2014

I am looking for the correct syntax to typecast a character array as an int. So I would be able to do something like this:

char ch[4];
//...Read characters from file into ch or something, etc...
int i = ( int ) &ch;

or

char ch[4];
//...Read characters from file into ch or something, etc...
int i;
strncpy ( ( char* ) &i, ch, 4 )

I want all the 4 characters ( or bytes ) of ch to be classed as an int. So we are taking the 4 bytes of the character array and placing them in 4 bytes of the integer? How would i go about this?

View 2 Replies View Related

C++ :: Testing For References To Identical Objects

Jun 18, 2014

I am checking to see if two references are bound to the same object. My instincts tell Me, "Check their addresses. If they match, they are bound to the same." At the same time, I have not found anything in the C++ standard which would support this approach. Am I missing something? Is there wording which backs up My instincts? Is there a standard function to do this?

View 4 Replies View Related

C++ :: Recursive Boolean Function - Compare Two Stacks And Returns True If Identical

Oct 21, 2014

The question is to write a recursive boolean function that compares two stacks and returns true if they are identical. This is where I get stuck:

If the top items of both stacks are the same, the recursive call always returns true, because 'true' is saved on top of the return stack.

Here is my code:
template<class Type>
bool identicals(stackType<Type> s1, stackType<Type> s2) {
if(!s1.isEmptyStack() && !s2.isEmptyStack()) {
if(s1.top() != s2.top())

[Code] ....

View 2 Replies View Related

C++ :: Popping From STL Containers

Feb 21, 2014

I've been working on a project that involves storing pointers to dynamically allocated class objects in an STL list, but trying to run it something's going wrong.

list<Actor*>::iterator it;
for(it = m_actors.begin() ; it != m_actors.end() ; ++it)
{
delete *it;

[Code]....

But it seems like that has a memory leak. Does pop_front() just call the destructor for the object, or will it delete a dynamically allocated chunk of memory? If not, how can I do that deletion to avoid a memory leak?

View 4 Replies View Related

C++ :: Dynamic Containers With Arrays?

Feb 14, 2015

Im trying to create a function that searches my array for a specific string, and then displays that string and the other content associated with it. I'm basically searching for a keyword within an array that has multiple strings with in each element.

View 4 Replies View Related

C++ :: Create Function That Calculates Sum Between Two Containers

Jul 1, 2012

I need to create function Sum() that calculates sum between two containers. Code below work fine except function Sum between two containers...

How I should re - write my code that everything work fine.

Condition of exercise is : "Also create a Sum() function that calculates the sum between two iterators. The function then uses the template argument for the iterator type and accepts two iterators, the start- and end iterator"

1>------ Build started: Project: HP2_ex2_iter, Configuration: Debug Win32 ------
1> main.cpp
1>c:all myс++ha level 7solutionlevel 7 homework overview of the standard template libraryhp2_ex2_itermain.cpp(47): error C2275: 'C1' : illegal use of this type as an expression

[Code]...

View 5 Replies View Related

C++ :: Custom STL Compatible Containers And Iterators?

Jul 18, 2012

So i made an STL compatible container.And to make this work I had to make my own iterator (derived from std::iterator).

What is the portable (if any) and "well behaved" thing to do in case of usage anomalies.such as iterating an iterator too far, or passing an invalid index to a operator[]

Looking at how VC++ does things in something like std::array or std::vector.

Code:

iterator_type& operator+=(difference_type offset)
{// increment by integer
#if _ITERATOR_DEBUG_LEVEL == 2
if (size < index + offset)
{// report error

[Code] .....

lots of names starting with underscores, so it's implementation specific. Is there even a "well behaved" thing to do ? Or is any such work always going to be compiler specific?

View 2 Replies View Related

C++ :: Containers That Doesn't Change Member Address

Jun 25, 2013

#include <iostream>
#include <vector>
using namespace std;
int main() {
int * ptr;
vector<int> data;
data.resize( 1000 );

[Code] ....

So I need container that doesn't rellocate their address, It doesn't need to be like vector that everything is in a single pointer such as

int * a = new int[2000];

I have a pointer pointing to a member of a container and it needs to remain valid... doing

vector<int *> Array;
// allocating
for( int i = 0; i < 1000; ++ i ){

Code] ...

Waste of time, allocating them and deallocate them seem to take some time too

a List is also not efficient enough because I access them based on index

It is not a int it is pointing to but a texture, for the sake of simpler example I pick int

So is there a container that doesn't change member address and allocate when it needs to expand ?

View 3 Replies View Related

C++ :: Manipulating Set Of Containers - Vector Of Vectors Of Objects

Mar 5, 2013

I need manipulating a set of containers. I created a vector that contained vectors of objects:

std::vector< std::vector<Terrain> > mapArray(num1, std::vector<Terrain>(num2));

where num1 and num2 are arbitrary numbers. and Terrain is the class of objects I'm trying to store.

I want to be able to use push_back on both the main vector and the vectors within the mapArray vector but I'm unsure of how to target the inner vectors with push_back. How to dynamically store a 2D array of objects.

View 10 Replies View Related

Visual C++ :: Creating Containers That Respond To User Actions?

Oct 16, 2013

I am looking for direction on what topic I should be reading up on. I am new to C++ and Windows MFC.

This is my real world problem, in the context of the application user. (these term do not refer to OPP concepts)

I want to create shapes (containers) in an application that will respond and collect other objects;

Imagine a Windows frame, containing several 2 dimensional squares. I want to be able to drag and drop marbles into the squares,and have the square retain and display the marbles in the square, in the order that they were dropped in.

How do I create the shapes, and how will the square sense when a marble is over it?

How would I create irregular shapes (a combination of lines and curves) that would be responsive to the marbles?

View 2 Replies View Related

C++ :: Smart Accessor Function For Multiple Data Containers?

Mar 14, 2012

Suppose I'm writing a program designed to simulate a large company. I'm interested in tracking each company employee by the location where they work. This company has perhaps a thousand different locations:

class Employee {
public:
AccessorFunction1(); // does something
AccessorFunction2(); // does something different
AccessorFunction3(); // does something completely different
protected:
// Some data

[code]....

Once employees are created and pointers to them are saved in the proper Location vector, I write an accessor function, OrganizeLocation(), designed to do a number of operations on a given vector. The problem is, I have maybe a thousand vectors. How do I call this function and specify which vector I want?

Currently, I'm using this clunky solution:

void Company::OrganizeLocation(int a){
switch(a) {
case 1: {
for(unsigned int i=0; i<LocationA.size(); i++) {
LocationA[i]->AccessorFunction1();
LocationA[i]->AccessorFunction2();
LocationA[i]->AccessorFunction3();

[code]....

The key point here is that whichever vector I choose to operate upon, I'll do the exact same procedure every time. I hate this solution because it results in very long and repetitive code not to mention its very error-prone when you re-editing all those "LocationA 's into "LocationB/C/D/etc."

void Company::OrganizeLocation( string $WhichOne$ ){
for(unsigned int i=0; i<LocationA.size(); i++) {
Location$WhichOne$[i]->AccessorFunction1();
Location$WhichOne$[i]->AccessorFunction2();
Location$WhichOne$[i]->AccessorFunction3();
}

Or, if it can't be done in C++, is there a better design approach? Ultimately I need the Company object to hold multiple vectors but use one compact accessor function to perform operations on just one of them.

View 5 Replies View Related

C++ :: Category And Constant Storage

Mar 14, 2013

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.

View 4 Replies View Related

C++ :: Unlimited Storage For Variables

Jul 12, 2013

I am working on a project and I need to save and work on very big numbers, let me take u an example :

E.g. I want to find the biggest prime number ( 2,3,5,7,... ) but I just know about int, double and etc. which have unlimited storage .

How to save very big numbers on the memory and use them ?

View 5 Replies View Related

C++ :: Declare Not Allocating Storage?

Jan 22, 2014

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?

View 9 Replies View Related

C++ :: Invalid Storage Class For A Function?

Mar 23, 2014

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.

Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>

[Code]......

View 1 Replies View Related

C :: No Permanent Storage During Program Execution?

May 22, 2013

Code:

#include <stdio.h>
int sum_array(int * , int );
int main(void)
{
int total = sum_array( (int []) { 1 , 2 , 3 , 4 } , 4 );
}

[code]....

We create an unnamed array "on the fly" that it means array has no permanent storage during the program execution?

View 11 Replies View Related

C++ :: Wedding Reception Data Storage?

Mar 4, 2014

I wanted to store information about a wedding reception and I'm having a few troubles with my program.

#include<iostream>
#include<windows.h>
#include <ctime>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;
#define on ,
void GREETING();

[code].....

View 1 Replies View Related

C/C++ :: Explicit Specialization Cannot Have A Storage Class

Jan 31, 2013

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:

enum SortReturnCodeEnum {LOWEST=1, HIGHEST=2, HIGHLOW = 3, IDENTICAL=4};
template<typename tKey>
static SortReturnCodeEnum DefaultCompare(typename ArgType<tKey>::ARGT Value1, typename ArgType<tKey>::ARGT Value2)
{

[Code]....

I could do a #define __GNUC__ but i was checking

View 3 Replies View Related

C/C++ :: Storage Class Specifiers Concept?

Feb 15, 2013

Write a program using all storage class specifiers?

View 2 Replies View Related

C++ :: How Item Storage System Is Supposed To Work

Feb 14, 2013

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 ....

View 2 Replies View Related

Visual C++ :: Read Excel File And Storage In Array

Nov 4, 2014

I wish to read an excel file which contains the table shown at the picture below.

I don't really know how to code the direct storage of the values in the appropriate array.

For example I wish to store the countries in an array of a string type.

could I have some piece of code which illustrates it (I mean the reading of an excel file and the direct storage of his value in an array).

View 1 Replies View Related

C :: Storage Types / Formatted Input / Output / Processing A Menu

Feb 1, 2013

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.

View 3 Replies View Related

C++ :: Access Serial Port - This Declaration Has No Storage Class Or Type Specifier

Feb 26, 2013

I am writing a code using Visual C++ to access serial port.

Code:
HANDLE hSerial= CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
DCB dcb = {0};
dcb.DCBlength=sizeof(dcbSerialParams);
dcb.BaudRate=CBR_1200;
dcb.ByteSize=8;
dcb.StopBits=ONESTOPBIT;
dcb.Parity=NOPARITY;

I am getting error in all last five lines in above code at dcb. and error is give below:-

Error: this declaration has no storage class or type specifier

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved