C++ :: How To Create Umbrella Type
Nov 20, 2014
Any way to create an "umbrella" type/class/struct of existing c++ types or windows types.
I want to address ~3 different structs with a single pointer and downcast but, they are not a part of the same hierarchy.
Is there a way that I could for example's sake, include a POINT and a RECT under some "umbrella" type so I can go like this:
// Working Variables
//---------------------------------------------------------
Umbrella* pUmbType1(NULL);
Umbrella* pUmbType2(NULL);
POINT ptExamp = { 0 };
RECT egRect = { 0, 0, 0, 0 };
// Typecast POINT and RECT to umbrella pointer
//---------------------------------------------------------
pUmbType1 = (Umbrella*)ptExamp;
pUmbType2 = (Umbrella*)egRect;
I want to do this, so I don't have to duplicate code for each type.
View 4 Replies
ADVERTISEMENT
May 21, 2014
So I am writing an assignment to Detect prime numbers and it works by Asking for how many values you are going to enter, and then saying "Enter value 1: "
Then you would input and it would calculate via for loop, and that part is working. However to make my program more foolproof, I devised a way for the user to be unable to "Break" the program by inputting characters or float values. Here is the code for that:
while(!(cin >> num)){ //num is some type (char, float, int etc.)
cout << "That is not at valid input, please try again" << endl; //"Error Message"
cin.clear();
cin.ignore(10000, '
'); //Clear and reset cin
cout << "Enter value " << n << ": "; //Re-Prompt User for input
//n is whatever value the for loop is on
}
and this code works fine, I was just curious about how i would turn it into a function. Preferably wiht the name: ValidateInput(Param1, Param2);
The Parameters of the function preferably would be the variable youre inputting and the message you want to prompt. So somehow i wish to have it so for the above example it would look like:
ValidateInput(num, "Enter Value " << n << ": ");
But I don't know exactly how to label either parameter part because I want it to work for chars, ints, floats etc. And I don't know what I want it to return if anything either.
View 1 Replies
View Related
Oct 17, 2014
i need to create a new integer data type called BigInt to store a big big integer, which includes Dint(8 bytes) and Qint(16 bytes)
here is the hint/
typedef struct BigInt {
Int data[2];
}
How can i "scanf" and "printf" them????
void ScanBigInt(const char *format, BigInt &x)
if format is “%dd” -> input Dint, if format is “%qd”--> input Qint
void PrintBigInt(const char *format, BigInt x)
View 3 Replies
View Related
Dec 31, 2014
well i create a State.h class
#ifndef STATE.H
#define STATE_H
class State {
public:
virtual void handle_action() = 0;
virtual void update() = 0;
virtual void render() = 0;
};
#endif //STATE.H
What i'm trying to create is a simple State Manager for SFML! I created another class that inherits State.
#pragma once
#include "state.h"
class FirstState : public State {
public:
FirstState();
~FirstState();
void handle_action();
void update();
void render();
};
So the question is this, each state that i have will inherit the State class. However, i wanted to perhaps add each state object into a vector array. But i'm not sure as to what data type it be? I have a state manager class that will contain the vector.
What i want to do is this, each game state will create an object that will inherit functions from the state.h class. I want to store them all in a vector array, but each object is clearly named different. My curiosity was wondering, since all those different states inherit the State.h class, can i simply create a State Object std::vector<State> *states; that will contain all those different state objects?
[URL]....
View 1 Replies
View Related
Aug 24, 2013
Can I create 1 variable that accept any type? And can I give it the NULL value too?
View 14 Replies
View Related
Apr 16, 2013
I am trying to create a class type structure using struct instead of classes.
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
struct myclass {
int * array;
int nelements;
[Code] ....
Guess what I am asking is using the pointer in the first code section better or is there another way'. I don't know about making the second code work.
View 3 Replies
View Related
Dec 4, 2013
I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?
View 6 Replies
View Related
Feb 1, 2015
I'm trying to create a new data type Data declared as int. What comes up to my mind is to create a structure like
Code:
typedef struct Data {
int number;
} Data;
but when I need to use the data I need to go through the structure. Is this a good way to declare a new data type?
View 2 Replies
View Related
Apr 27, 2013
I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.
My current code is:
Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()
[Code]....
View 4 Replies
View Related
Dec 21, 2013
how to convert an element of int type of an array to char type?
View 2 Replies
View Related
Aug 31, 2014
I have a function like this:
template<typename T>
void f() {
//...
[Code]....
list contains, in order: A, B and C in any order, D, E
I am thinking it is possible with some clever template and polymorphism combos, but maybe not. As a last resort I know how to make it work by storing static type information in each class, but I'd like to avoid that if possible.
View 6 Replies
View Related
Oct 26, 2013
I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.
Code:
* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}
[code]....
View 7 Replies
View Related
Apr 10, 2014
I need to create a project that create a automated backup of a file.
i will get the file from C:/Folder/file.exe and move for a other created folder, but.. in every time that user make this backup, a folder will be created with year, month and date, like: C/Folder2/2014/April/16:42/file.exe.
View 4 Replies
View Related
Jul 22, 2013
I need to use the type RectangleF as a built in type in c++ ie I need to declare a variable rect as RectangleF rect;
what do I have to include to be able to do this.
View 2 Replies
View Related
Oct 12, 2013
Let me put it into the code snippet:
/**
This class build the singleton design pattern.
Here you have full control over construction and deconstruction of the object.
*/
template<class T>
class Singleton
[Code]....
I am getting error at the assertion points when i call to the class as follows:
osgOpenCL::Context *cxt = osgOpenCL::Singleton<osgOpenCL::Context>::getPtr();
I tried commenting assertion statements and then the debugger just exits at the point where getPtr() is called.
View 7 Replies
View Related
Aug 10, 2014
How to change an enum type variable to a string type variable?
View 2 Replies
View Related
Feb 10, 2013
For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:
undefined reference to 'BST<void>::insert(int, void*)'
Stemming from the call in main line 16.
my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp
Generic_Tree:
template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;
[Code] ....
I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.
View 4 Replies
View Related
Mar 7, 2013
I recently came across the issue of not being able to type in my cmd console. I was working on a project in MSV; while starting a new one I was unable to type in the console. *After compiling with no errors.
#include <iostream>
//@author Will A. Training Exercise Grade Programming
int main()
[Code].....
Although in another project I worked on previously I still may type in the console.
View 10 Replies
View Related
Apr 20, 2014
I have a class named backgroundObstacleManager that I created and another class Pit that have to interact with each other however I'm getting an error.
//backgroundobstacleManager.h
#include "Pit.h"
class backgroundObstacleManager {
public:
backgroundObstacleManager();
void update(sf::RenderWindow *app, Player *Jerry);
[Code] .....
The error is
/media/justin/Linux Data/Programming/C++/jerry and the magic bannana/backgroundObstacleManager.h|34|error: ‘Pit’ does not name a type|
View 2 Replies
View Related
Jun 13, 2013
Q. Consider the following C declaration.
int x[10], y,z;
What kind of error does following statement contain?
z == x +y;
a. Syntax error
b. Semantic error
c. logical error
d. All of the above
According to me it should be option a, but I am confused, how to get confirm answer with explanation.
View 11 Replies
View Related
Dec 12, 2013
unknownType func( void );
std::vector< /* type of unknownType */ > objects
The source of my question is trying to make a templated button:
template <typename T>
class Button
{
T m_func;
[Code]....
View 2 Replies
View Related
Apr 20, 2013
it is not possible to get a type from an object, only from a type. Even with auto, you can only instantiate another type of the same type.I'd like to get a type from an object given another type, mainly because it is less typing and less error prone.
Some psudocode:
Type1 A<X, Y> a;
int b;
Type2 a.InnerType<b>::type c; // obviously won't work
A work around I thought of would be to use functions:
Type1 A<X, Y> a;
int b;
auto c = a.getInnerType(b);
Which is kinda interesting and looks like the way I'm going to go. However, I'm just wondering if there is any other ways of doing this as I don't really want to instantiate an object if I can avoid it (though the optimizer will probably just dump it anyway).
View 2 Replies
View Related
Jul 22, 2013
#include<iostream>
#include<cstdio>
#include<list>
[Code]....
In the last line "graph.edge{x,y,w}" it says typename is not allowed? I have used nested class edge and pushing vertices and their weight in elist vector which is of type edge.
View 5 Replies
View Related
Nov 7, 2013
I'll just let you look at the code, says the error occurs at line 14.
#ifndef SIMPLE_LOAN_H
#define SIMPLE_LOAN_H
#include<string>
#include "loan.h"
class simple : public loan {
[Code] ....
View 1 Replies
View Related
Dec 9, 2013
I get this "dll.cpp:12:8: error: 'string' does not name a type EXPORT string name(){"
when i try to compile this
#include <stdint.h>
#include <string.h>
#if defined(WIN32) || defined(_WIN32)
#define EXPORT __declspec(dllexport)
[Code] ....
I am exporting the functions, and I am making a dll.
View 2 Replies
View Related
Feb 8, 2015
I'm attempting to pass a couple of variables over to my Item.cpp class, that is description and item_price. However under item.set(description,item_price), i get three errors. One under the . (period) saying : expected an identifier and two more under description and item_price stating that variable " xxx " is not a type name.
Main.cpp
#include <iostream>
#include "item.h"
using namespace std;
using namespace items;
int main(){
int n;
[Code] .....
View 11 Replies
View Related