C++ :: Class To Manage Pointers Better - Some Errors

Nov 19, 2013

I wrote a class to manage pointers better (because I am making a large program and don't want to call a constructor on somthing that was already deleted... etc...), but I am getting some compiler errors. I'm not sure what to do.

here is the class prototype:

template<typename type>
class pointer_class{
public:
pointer_class() : dat(NULL), del(false) {}
explicit pointer_class(const pointer_class<type>& d) : dat(NULL),

[Code].....

View 19 Replies


ADVERTISEMENT

C++ :: Variable Inside A Class - How To Manage Memory Allocation

Jul 30, 2014

recently I developed a class header only in C++ to deal with byte arrays. Since I developed programs in other languages that had some libraries to dial with byte arrays, I developed one that the syntax is very similar to other languages.

Since I'm not very familiar with memory management, I was concerned about somethings I've read about (ex: memory fragmentation).

Here is a very simple example of my practice:

class ByteArray {
public:
ByteArray(size_t size) {
buffer = (int8_t*)malloc(size);
}

[Code].....

The class is intended to be used as part of comunication protocol in a webserver, byte arrays are created and destroyed a lot. Should I use pools? Is there a better practice? Am I doing everything wrong (laugh)?

For those who wants to see the entire class: [URL]

View 9 Replies View Related

C++ :: Class Course / Constructor Errors

Mar 22, 2014

# include <iostream>
# include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
class Course
// Creating the class Course

[Code] ....

Errors: Warning1warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

[Code] .....

I have to create an Array of type Course and then fill its member dats using various member functions. Those errors are caused by some Constructor defect, which I dont really know what it is.

View 2 Replies View Related

C++ :: Errors While Writing Car Class Program

Oct 9, 2013

Ive been writing this code all day and these errors have been killing.

Instructions:
Car Class:
Write a class named Car that has the following:
year. An int that holds the cars model year.
make. A string object that holds the make of car.
speed. An int that holds the cars current speed.

In addition, the class should have the following member functions.

Constructor. The constructor should accept the car's year and make as arguments and assign these values to a object's year and make member variables. The constructor should initialize the speed member variable to 0.

Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's year, make, and speed member variables.

accelerate. the accelerate function should add 5 to the speed member variable each time it is called.

brake. The brake function should subtract 5 from the speed member variable each time it is called.

Demonstrate the class in a program that creates a Car object, and then calls accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. The, call the brake function five times. After each call to the brake function, get the current speed of the car and display it.

Errors: error C2061: syntax error : identifier 'stringm'
error C2533: 'Car::{ctor}' : constructors not allowed a return type
error C2511: 'Car::Car(int)' : overloaded member function not found in 'Car'
see declaration of 'Car'
fatal error C1903: unable to recover from previous error(s); stopping compilation

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

[Code].....

View 2 Replies View Related

C++ :: Finding Errors In Class Template

Nov 17, 2014

I have to find at least 5 errors in the following class template. I have found three and it now compiles, here is the template

#include <map>
#include <utility>
template <class T> class foo{
public :
foo(T bar1, T bar2){
_bar1.push_back(bar1);
_bar2.insert( std::pair<T,T>(bar1,bar2) );

[Code] ....

The errors I believe I have found are as follows: the vector library has not been added, the map requires two type arguments rather than one and the object which is created in main doesn't pass any values to the constructor. I fixed all of these errors and the code now compiles without errors, however the problem asks for five.

View 1 Replies View Related

C++ :: Compiling Errors In Template Class?

Mar 22, 2014

what my compiling errors mean, and what I should do to fix them: The following is my header & Implementation files. Note, the purpose of this class is a built in Array.

Header File:

#ifndef ARRAY_H
#define ARRAY_H
#include <iostream>

[Code].....

View 5 Replies View Related

C# :: Definition Errors After Changing Name Of Class

Jan 31, 2014

I changed the name of my Invoice class to 'Application' and then it generated errors such as follows

Error9'Invoice.Invoice' does not contain a definition for 'Documents' and no extension method 'Documents' accepting a first argument of type 'Invoice.Invoice' could be found (are you missing a using directive or an assembly reference?)c:userskeildocumentsvisual studio 2013projectsinvoiceinvoicewritefile.cs1840Invoice

Error3'Invoice.Invoice' does not contain a definition for 'Run'C:UsersKeilDocumentsVisual Studio 2013ProjectsInvoiceInvoiceProgram.cs1921Invoice

I have added my classes here, lso I have added the sln to this post.

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code].....

View 5 Replies View Related

C/C++ :: Finding Errors In Class Template?

Nov 18, 2014

I have to find at least 5 errors in the following class template. I have found three and it now compiles, here is the template

#include <map>
#include <utility>
template <class T> class foo{
public :

[Code]....

The errors I believe I have found are as follows: the vector library has not been added, the map requires two type arguments rather than one and the object which is created in main doesn't pass any values to the constructor. I fixed all of these errors and the code now compiles without errors, however the problem asks for five.

View 2 Replies View Related

C++ :: Making Class Constructor Within Namespace And Keep Getting Errors

Mar 25, 2013

I'm trying to make a class constructor within a namespace and I keep getting errors like: "'<variable>' is a nonstatic data member of class '<class>'" for when I try to setup parameters, and "Incomplete type is not allow" whenever I try to write out my function definition. Here's what I'm doing:

namespace test {
class blah;
} class blah {
typedef int var[5];

[Code] .....

Also I'm unsure why there is a parameter of 'const blah &' when I mouse over blah(); (using Visual Studio 2010) within the class definition. It tells me 'blah::blah(const blah &)' and I am unsure where the parameter comes from. How can I resolve these issues?

View 4 Replies View Related

C++ :: Class / Header File Related Errors

Sep 22, 2014

Here's my class/header, and Visual studio Output.

Injection point/instantiation.

int main() {
Player player;

Call to a public method:
while(!isWin("x", board) && !isWin("o", board) && whoGoesFirst == "p") {
printBoard(board);
board = player.playerTurn(board);

[Code] .....

Output:
1234
1
1> Player.cpp
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C2143: syntax error : missing ';' before '<'
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C2238: unexpected token(s) preceding ';'

View 2 Replies View Related

C++ :: Creating Array Of Pointers To Base Class To Point To Derived Class Objects Dynamically

Jan 16, 2013

Please consider the following code :

#include <iostream>
using namespace std;
class superclass;
class subclass1;
class subclass2;

[Code] ....

As you can see I want to create a dynamically allocated storage of references to a parent class each of which can then point to a child class, how ever I do not know how to extract the child class out again from that array so i may access its variable b.

View 2 Replies View Related

C++ :: Template Class Type - Unresolved Link Errors

Jun 25, 2013

I'm getting unresolved link errors when I attempt to compile.

dNode.h

#ifndef DNODE_H
#define DNODE_H
template <class T>
class dNode {

[Code] ....

ERROR:
Error1error LNK2019: unresolved external symbol "public: __thiscall dStack<double>::dStack<double>(void)" (??0?$dStack@N@@QAE@XZ) referenced in function "void __cdecl stack_test(void)" (?stack_test@@YAXXZ)main.objprog09
Error2error LNK2019: unresolved external symbol "public: virtual __thiscall dStack<double>::~dStack<double>(void)" .......

View 3 Replies View Related

C/C++ :: Repeating Errors On Overloading Non Member Class Program

Oct 21, 2014

I am having a issues with an assignment in my class and don't really understand why. I am getting undeclared identifier errors even though I have declared and I am also getting an error. Here is the code:

#include "stdafx.h"
#include <iostream>
#include <cassert>

[Code].....

Last time I came to you all with an error it was a simple brain fart on my part but I don't think this one is like that. I would love to tell you what the program is supposed to do but I still do not really know, which might be part of the problem. I guess it outputs different sized rectangles...

View 7 Replies View Related

C# :: GTK - How To Manage Sizes Of Widgets

Aug 3, 2014

I create new dialog window. I add container Fixes and change Fixed properties : - AutoSize, +Expand, +Fill to enable other widgets. I add Text View, Textview is inside GtkScrolledWindow which has property X and Y but not Height and Width. If GtkScrolledWindow has scrollbars, its size is fixed, if not - size depends on the content Textview and grows when I type text. I want not to grow control if I type Text but want my own size. It is possible?

View 7 Replies View Related

C++ :: How To Manage Popup Windows

Mar 24, 2014

I’m working on a project that has many pop up windows. They are not organized properly and things are getting messy. I’m wondering if there are any common practice or design patterns for solving this problem.

I’d like to give some concrete examples:

1. my program connects to two different tcp ports on the same ip. cutting off any of them, the user will be notified with a MessageBox. But in case of unplugging network cable, both message box will show, which is unnecessary.

2. we provide a shortcut key to display a setting dialog. However the program can also show the same dialog when certain event happens. If the user opens the setting dialog already, those event will still trigger a second setting dialog.

3. when application settings are not correct, user will disconnect from the server and an error dialog will show up and terminate the program. But if the user knows about the situation and has opened the setting dialog to fix the issue, the error dialog will terminate his work. which is bad.

I don’t know how to deal with this window management problem in a complex software project. Of course, I can solve the issue case by case by checking if certain dialog is shown before displaying another dialog. But there are too many cases, when the code base gets big, this is not practical. There must be some generic solution I think.

View 4 Replies View Related

C++ :: Compiler And Linker Errors For Linked List Class And Application

Aug 31, 2014

I am trying to write a program that will take a list of integers from a file and write them to another text file. I've been banging my head at this for days trying to get it to compile as it is riddled with linker and compiler errors.

**************************header*************************

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class T>
class linkedList {

[Code] ....

View 6 Replies View Related

Visual C++ :: Manage Serial Communication With A Pedal

Jan 17, 2013

I wrote a class pedal that allows to search for the serial port on which the pedal is connected. Therefore I send a request to the pedal and set up a timer event of 20 ms. If no reply, I search for the next serial port.

When found I send configuration to the pedal and set another timer event of 200 ms that requests for pedal state. It runs fine.

Now if the pedal is disconnected then connected again I would like it to run again.

Therefore I set another timer event every 2s that launches all what I described above.

The trouble comes because the 20 ms timer event doesn't run and I do not understand why.

View 3 Replies View Related

C++ :: Vector Of Pointers - Abstract Class

May 13, 2014

I need to create a vector of pointers and hold the book objects in it. then i have a virtual function in my books which is a pure virtual in LibraryItems. When i try to add the books object in my code, i understand that since the scope runs out there is no object that is added. so when i run print it gives me an error.

#include<iostream>
#include "books.h"
#include "library.h"
#include <vector>
using namespace std;

int main(int argc, char * argv[]) {
vector<LibraryItems* >libraryInfo;

[Code] .....

View 4 Replies View Related

C++ :: Class With Pointers And Dynamic Arrays

Apr 25, 2014

Class with Pointers and Dynamic Arrays

View 2 Replies View Related

C/C++ :: Function Pointers From External Class?

Jun 8, 2014

How can i use a function pointer from external class? Say we have a class tuna

Tuna:

int foo(){
return 45;
}
int (*foobar)();

[Code].....

View 9 Replies View Related

C++ :: How To Hold Pointers / References To Abstract Class

Nov 15, 2014

I have an abstract class named Terrain, and a class named RoadMap, which supposed to hold an N*N array of Terrains. But I'm not sure what type should the RoadMap class hold:

Code:
#ifndef TERRAIN_H
#define TERRAIN_H
class Terrain {

[Code] ....

I can't use an array of refernces here, so I tried this:

Code: Terrain** terrain; and then I thought this was the way to go:

Code: Terrain (*terrain)[]; But now I'm not sure.

The N*N matrix size supposed to be determined according to a given input... What type should I use there?

View 2 Replies View Related

C++ :: Hold Vector Of Pointers In Same Class As Instances Of Those Objects?

Feb 10, 2015

Using SFML, I had a Board class which held multiple vectors of all of my object types in the game, and then it also held a vector of pointers to the memory addresses of these object instances, like this

class Board{
//...
std::vector<AbstractObject*> GetAllLevelObjects(){ return allLevelObjects; }
//so these are used to hold my object instances for each level

[Code]....

When looping through this vector and drawing the sprites of the objects, I get the runtime error 0xC0000005: Access violation reading location 0x00277000. I solved this error by storing the vector of pointers in the class that holds my Board instance, but I'm wondering why only this solution worked? Why couldn't I just have my vector of pointers in the same class that the instances of those objects were in?

View 2 Replies View Related

C++ :: Storing Variable Size Pointers Array As Class Variable

Mar 2, 2013

This problem is best explained by looking at its output below. I stored 15 different values but when retrieved some are wrong.

#include <iostream>
using namespace std;
class A {
public:
int ** pointer;

[Code] ....

I need to store and retrieve the 15 different values correctly. How to solve this? The main thing is, I need to store the pointer in class A objects.

View 6 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C++ :: Comparing Char Pointers To Integer Pointers

May 21, 2013

I am a little confused while comparing char pointers to integer pointers. Here is the problem:

Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";

When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;

As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};

If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??

View 2 Replies View Related

C++ :: Seg Fault Run Errors

Mar 25, 2014

identify the reason why I am getting a seg fault run error? I hate to bother but I've been trying for several days now to fix the same function.

class adjacencyList {
public:
explicit adjacencyList(int size);
void buildGraph(Edge inEdge);
void print();

[code].....

View 6 Replies View Related







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