C++ :: Class Safe Array Type Print Function Not Working When Called
Oct 22, 2013
I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.
Header File:
//safearrayType Header File
class safeArrayType {
public:
void print() const;
void insertAt(int location, const int& insertItem);
safeArrayType(int firstPlace=0, int maxPlace = 100);
[Code] ....
ResultsEnter the first bound of yourlist: -3(this was my input)
Enter the last bound of yourlist: 7(this was my input)
Press any key to continue...
View 1 Replies
ADVERTISEMENT
Apr 29, 2014
Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a non-negative whole number.
Include a mutator function that sets the counter to a count given as an argument. Include member functions to increase the count by one and to decrease the count by one.
Be sure that no member function allows the value of the counter to become negative.
Also, include a member function that returns the current count value and one that outputs the count. Embed your class definition in a test program and run sufficient tests to verify it all works correctly.
View 3 Replies
View Related
May 7, 2013
I am new to C++ programming and i have a small assignment.
How to implement a thread safe class to manage a queue of objects. Accessing the front of the queue should be a blocking operation when the queue is empty.
View 4 Replies
View Related
Oct 26, 2012
Here are the classes:
BaseClass.h
Code:
class BaseClass {
public:
BaseClass();
virtual ~BaseClass();
virtual void printStuff() const;
[Code] ....
When I call printStuff, the DerivedClass's function gets called. Now, if I remove the const part from the DerivedClass's printStuff function, we call the BaseClass's printStuff function.
View 4 Replies
View Related
Nov 27, 2013
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
View 3 Replies
View Related
Feb 3, 2013
I'm trying to template the return type for this function (component), I've looked around for example code but there doesn't seem to be any exactly like what I want.
Entity.hpp
class Entity {
public:
Entity();
unsigned int id = 0;
Component& addComponent(std::string);
[Code] ....
Error : 'ent1.component<HealthComponent>' does not have class type
View 2 Replies
View Related
Jan 10, 2015
My g++ compiler is telling me that said printTest() is not part of the class. I have presented it in header class and implemented it in .cpp class but still keep getting the error. Compile and compile error -
blackjack > g++ -Wextra -pedantic -std=c++11 Deck.h Deck.cpp test.cpp ;
test.cpp: In function ‘int main()’:
test.cpp:6:6: error: request for member ‘printTest’ in ‘test’, which is of non-class type ‘Deck()’
test.printTest();
My Code -
//Deck.h
#include <iostream>
#include <string>
class Deck{
public:
Deck();
void printTest();
[code].....
View 3 Replies
View Related
Sep 6, 2013
I have a function that concatenate the strings in an array(2D)
Ex 1: Sean Connery Micheal King James Wood
Result: SeanConnery MichealKing JamesWood ...
The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this
Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..
It adds to first name. Why?
Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()
[Code] .....
View 4 Replies
View Related
Sep 1, 2013
//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;
Point::Point() { //Initialise the point to the origin.
[Code] ....
void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"
How do I accomplish this? When i test with cout << _point1.print(), there's an error:
[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'
View 4 Replies
View Related
Apr 28, 2013
I want to use this array as part of my class. I have tried several different angles trying to get it to work but with out success. I have been checking to see if it works by simply using "cout << dayName[3];" It is printing nothing at all. What is the proper way to initialize this array of strings?
First I tried this:
const string dayName[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
then I tried this:
const string dayName[7];
dayName[0] = "Sunday";
dayName[1] = "Monday";
dayName[2] ="Tuesday";
dayName[3] ="Wednesday";
dayName[4] ="Thursday";
dayName[5] ="Friday";
dayName[6] ="Saturday";
My implemetation file code and my header file code is here (header first):
//dayType.h, the specification file for the class dayType
#include <iostream>
#include <string>
using namespace std;
class dayType{
[Code] .....
View 4 Replies
View Related
Mar 30, 2014
I am having trouble with the array pointer and with the variables. I don't seem to have the pointer set up because the additional times the array is called it is empty. Also, if I don't use integers the program drops through. where I am going wrong?
Question is in the code
/*
NumClass
Main.cpp
*******************************************************************************************
*
* Design a class that has an array of floating point numbers. The constructor should accept an integer argument and dynamically allocate the array to hold that many numbers. The destructor should free the memory held by the array. In addition, there should be member functions to perform the following operations:
*
**Store a number in any element in of the array
[code].....
View 1 Replies
View Related
Jul 19, 2013
I have a class "Result" with a single template function Set(const std::string& arName, T& val) and a specialization of this function Set<Real>(const std::string& arName, Real& val) where Real is a typedef for double. The class is in a shared library and I use it in my main program. If I do result->Set<GLOBAL::Real>("U", 100.0); the wrong template function is called!
I check this by the output with std::cout.
Maybe it's a problem with the typedef.
If I link the object file of the Result class directly to my main program (no shared library), it works.
typedefs.hpp:
namespace GLOBAL {
typedef double Real;
} results.hpp
#include <iostream>
[Code] ....
View 3 Replies
View Related
Mar 6, 2015
I am writing a program with FLTK and in event handling part wanted to send the address of the handler function to callback function. Type cast just does not work.
Code: btnOpenDB->callback(&FLUI::WndMain::DBOpenBtnClick_scb, reinterpret_cast<void*>(&WndMain::DBOpenBtnClick_cb));
I want to cast "a pointer to a class member function which accepts one argument" to a void pointer. After all it is just an address. So it is logically possible to cast it. Isn't it? Actually an static_cast should be enough!
View 9 Replies
View Related
May 17, 2013
When the below is done, does it call the constroctor only, and if yes, constructors do not have return types so how does it work? is there anything behind the scene?
wxAddHandler(new wxPNG_HANDLER);
and
sf::RenderWindow(sf::VideoMode(...),...);
View 6 Replies
View Related
Aug 6, 2014
I've written this class and struct to create a singly linked list. The data is stored in the binary file which I've opened and read. I'm trying to load said data into a class type array. The errors I'm getting are "incompatible types in assignment of 'StatehoodInfo' to char[3]" Lines 130-134 is what I was working on.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring> //For char[] string functions
[Code] .....
View 2 Replies
View Related
Nov 1, 2014
I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.
Code:
#include<stdio.h>
void display(int array[],int size) {
int i;
[Code]....
With this code I want to print the five elements from the element present in [0][4].
But shows an error that
Code:
D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?
View 3 Replies
View Related
Jan 19, 2013
Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {
[Code].....
But when I try to call it, trying to copy my previous method,
glutKeyboardFunc(Player1.playerControls);
I get an error
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.
View 2 Replies
View Related
Feb 23, 2015
Is there any way to track what functions from what class are called at runtime? What I mean is a list of functions or classes which have been called at runtime.
View 1 Replies
View Related
Feb 18, 2015
I am creating a class called time and we've had to do operator overloading for <, > , <=, >=, ==, !=, ++, --, >>, <<, * , +, and -.
Well I have done and error checked them all. The only one I cannot seem to get right is the minus and its because of the error checking. I am having issues with times like this
t1 = 0:0:2:3
t2 = 0:0:1:4
t1 - t2 should equal 0:0:0:59 but it returns 0:0:1:-1.
(days:hours:minutes:seconds)
I need it to check for all cases and I just do not know how. Here is the code I have so far:
time operator- (const time& x, const time& y){
time subtract;
subtract.days = x.days - y.days;
subtract.hrs = x.hrs - y.hrs;
subtract.mins = x.mins - y.mins;
subtract.secs = x.secs - y.secs;
[Code] .....
View 1 Replies
View Related
Nov 3, 2014
I have a class Square that is composed of two Points, I pass the former to the Square as references (second ctor) and two Points are created.
The problem is, at the end of the program, 4 Points are now being deleted which suggests that somewhere copies were made (regardless of the references) and the m_p1, m_p2 have different addresses than p1 and p2.
#include <iostream>
using namespace std;
class Point {
public:
Point();
Point(double x,double y);
double printCor() const;
[Code] .....
Even though, the objects were passed to the ctor by references, the copy constructor (compiler generated) for Point was called and now we have two points and an object square with distinct Point objects.
View 3 Replies
View Related
May 2, 2014
I'm having trouble with my for loop near the end of the program was able to print everything else.
Sample Output:
*** end of 27610_Arrays04.cpp program ***
City City Points
--------------- 1---5----10---15---20
Belvidere **********
Freeport ********
Byron ************
Stillman Valley ***************
Rockford *********
*** end of 27610_Arrays04.cpp program ***
Input:
TODO #1: complete the coding of the points array
An integer array of 5 numbers: 10, 8, 12, 15, 9
TODO #2: complete the coding of the cities string array
An string of 5 city names intialized to:
"Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"
Compile-time arrays with initialization lists.
Processing & Output:
TODO #3: complete the coding of the call to the printStars() function
TODO #4: code the printStars() function
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void) {
/* declarations ------------------------------------------------*/
[Code] ....
View 2 Replies
View Related
Feb 15, 2014
This exercise is from C++ primer 5th edition. I have not understood everything about constructors, mainly about how they function.
Work prior to the exercise was creating a class called screen with some specifications. This is the class:
Code:
class screen{
public:
using pos = string::size_type;
screen() = default;
private:
pos height = 0;
pos width = 0;
pos cursor = 0;
string contents;
};
The exercise goes as follows:
Exercise 7.24: Give your Screen class three constructors: a defaultconstructor; a constructor that takes values for height and width and initializes the contents to hold the given number of blanks; and a constructor that takes values for height, width, and a character to use as the contents of the screen.
Giving the screen a default constructor was easy. The next part is probably easy aswell, I just dont understand what they mean when they say "and initalize the contents to hold the given number of blanks" and something in the 3rd part when they say "character to use as the contents of the screen".
Think I have made a breakthrough... Would the constructor for the second part look like this:
screen(pos ht, pos wd) : contents(ht*wd) {}
or something?
View 8 Replies
View Related
May 25, 2013
the value of C(k,n) are known as the binomial coeficient and can be arranged in triangle that was known as pascal triangle.
i was been asked to create a program that can display rows up to n=9 using print array function.
C(k,n) = C(k-1,n-1) + C(k,n-1)
how should i start?
View 3 Replies
View Related
Jul 20, 2013
The printArray function should take in the dynamically created array and the size of the array as parameters. It should print out the contents of the array.
#include <iostream>
#include <string>
using namespace std;
[Code].....
My problem is that how to write the code to print the array using pointers. I've been stuck for awhile trying to figure it out.
View 2 Replies
View Related
May 4, 2013
I am working on this project where I need a function to be called every second. At this time, I am thinking that I have to create a thread but I am clueless on how it will get called every second.
View 5 Replies
View Related
Nov 24, 2014
I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:
#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);
[Code] ...
View 3 Replies
View Related