C/C++ :: Storage Class Specifiers Concept?
Feb 15, 2013Write a program using all storage class specifiers?
View 2 RepliesWrite a program using all storage class specifiers?
View 2 RepliesWell, basically, what I've been doing was creating a class that would implement the concept of Double Linked List, but that would behave like a queue ( the STL implementation is deque, or Double Ended Queue ).
The problem occured when I have been trying to generalize the class using templates. I mean, why use only integers ? Why not double or char or what not ?
Worked perfectly before including all the template stuff..
// Source.cpp <=> Main.cpp
#include <iostream>
#include "DList.h"
using namespace std;
int main(void) {
DList<int> *list;
list = new DList<int>();
[Code] .....
The errors returned by the compiler:
Error1error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
Error2error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
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]......
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
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
let me show you the (simple) code:
Code:
#ifndef DUCK_H_
#define DUCK_H_
#include<iostream>
using namespace std;
class Duck
[Code].....
When I compile, it says: "error: 'virtual void Duck::display()' is protected" how come I can't gain access to MallardDuck's display(), which is public?
Is it possible to apply Print Conversion Specifiers to a single value multiple .
simply put ,
printf("%.1s%6lf
", perimeter_Circle);
I want one digit precision and 7 tab space on this item.
i have the following error defines.h:14:23: error: two or more data types in declaration specifiers, the begining define.h source code is (the line 14 is in red):
Code:
/* $Id: defines.h 3492 2011-09-18 20:44:09Z nekral-guest $ */
/* some useful defines */
#ifndef _DEFINES_H_
#define _DEFINES_H_
[Code]....
Can validate if my code implements the concept of insertion sort. The program is executing successfully. Just need a verification!
Code:
int i,j,k,a[100],n,num,min,max,temp;
printf("Enter array size: ");
scanf(" %d",&n);
printf("
Enter the numbers:");
for(i=0;i<n;i++)
scanf(" %d", &a[i]);
[Code] ....
I am not getting the real concept of delete operator. If it deallocates the memory, then why i am getting such output..!!
int main() {
int *a , b=5;
a = & b;
cout << *a << endl;
delete a;
cout << *a;
getch();
return 0;
}
Output:
5
5
I would like to create program which will analyse bitmap so would need good concept to save data. I am interested about the theory and I realize that i must to think this carefully because bad concept could create insufficient memory or inefficient program. Basically I want my program work with HSV or HSL model so I would need to convert the bitmap to HSL, but I am not sure if I should convert it first and then analyse all pixels or should I start to analyse the bitmap and make the conversion to HSL during it. But my main question is what method to choose to save the data in memory.
Even that I would start with very small, it should work also with bigger image like image having 1200 or even 4200 px on height. So the program should first analyse all columns of pixels in the image so for example 1200x800 px image has 1200 columns. So I would like to know if is it possible to create such object which would have such structure like this
Obj->basicColumnData->black->columns[name]->group
and in the place of columns should be placed data for every column. I would look for groups of pixels in the column, so in the result the column x could bear e.g. 500 groups of information and every group should contain the range of pixels e.g. group 1 should contain y value from 0 to 20, group 2 should contain value from 25-27 and so on. So I would create 1200 columns bear many of groups. This would be contained in "black" or "white" member to contain the data. This is just simplified idea, but the whole object should contain next data not just basicColumnData... So there should be another members bearing information calculated from the selected data.
So my question is what kind of method of saving data use for this? Should I use heap and dynamic allocated memory or should I create custom class, which will define every member, but these members will have to be dynamic memory? With the dynamic memory is there problem that there could be not enough memory to create such big object?
Create an a simple Payroll Management Application using the concept of Binary Tree. The program will allow you to add, sort, view, search record. The application have also the capability to save and retrieve data in a file.
View 1 Replies View RelatedI 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 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 ?
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?
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?
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].....
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.
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 RelatedI 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).
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 RelatedThere are two ways to access the members of class A inside class B:
1) Making an instance of class A in class B
2) Deriving class B from class A
So what is the basic difference in both ways as we can do same kind of work with both ways?
The case is like
class B{
public:
somedata;
somefunction();
}
class A{
public:
data;
function();
}
in somefunction i want a pointer to current object of class A m new to c++
Say I have 3 classes:
class Player {
public:
virtual func1();
[code]....
Say in my main class, I have a function fight(Player p1, Player p2) and I would like to do something like this in the fight function, given that p1 is the human and p2 is the computer:
//function fight()
fight(Player p1, Player p2) {
p1.func2();
}
//using function fight()
fight(human, computer);
When I compile the program, I got this: error: ‘class Player’ has no member named 'func2()' What can I do to allow p1 to call func2 inside fight()? I'm not allowed to use pointers as the parameter for fight() and have to use the signature fight(Player p1, Player p2).
The compiler creates virtual table for the base class and also for the derived class whether we override it or not.
That means each class has separate virtual table. when we get the size of the each class with out any data members... the size of base is -- 4 bytes(64 bit) and the size of derived is -- 1
The size of base class 4 is correct since it creates the virtual pointer internally and its size is member data + virtual pointer, but it in this case I have included any data members so it has given 4 byts.
But why in case of derived is 1 byte, since it the derived class has overridden the virtual function from base, this will also contains the virtual pointer which will be pointing to derived class Vtable, it the size of the class suppose to be 4 instead of 1 byte.
#include<iostream>
class A{
public:
[Code].....
I have my main.cpp like this:
#include <iostream>
#include "curve1.h"
#include "curve2.h"
using namespace std;
int main() {
Curve1 curve1Obj;
Curve2 curve2Obj;
[Code]...
Base class Score has two derived classes Curve1 and Curve2. There are two curve() functions, one is in Curve1 and other in Curve2 classes. getSize() returns the value of iSize.
My base class header score.h looks like this:
#ifndef SCORE_H
#define SCORE_H
class Score {
private:
int *ipScore;
float fAverage;
int iSize;
[Code]...
You can see that I have used curve1Obj to enter scores, calculate average and output. So if I call getSize() function with cuve1Obj, it gives the right size that I took from user in enterScores() function. Also the result is same if I call getSize() in score.cpp definition file in any of the functions (obviously).
.....
The problem is when I call curve() function of Curve2 class in main (line 23) with the object curve2Obj, it creates a new set of ipScore, fAverage and iSize (i think?) with garbage values. So when I call getSize() in curve() definition in curve2.cpp, it outputs the garbage. .....
How can I cause it to return the old values that are set in curve1.cpp?
Here is my curve2.cpp
#include <iostream>
#include "curve2.h"
using namespace std;
void Curve2::curve() {
cout << "getSize() returns: " << getSize() << endl; // out comes the garbage
}
Can I use a function to simply put values from old to new variables? If yes then how?