C++ :: Function Non-class Type?
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
ADVERTISEMENT
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
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
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
Oct 7, 2014
How to initialize a static member of a class with template, which type is related to a nested class?
This code works (without nested class):
#include<iostream>
using namespace std;
struct B{
B(){cout<<"here"<<endl;}
};
template<typename Z>
[Code] ,....
View 1 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
Nov 30, 2013
I am trying to pass a class as a type to a template class. This class's constructor needs an argument but I cannot find the correct syntax. Is it possible?
Here is an example of what I described above. I did not compiled it, it is for illustrative purpose only. And of course argument val of the myData constructor would be doing something more useful than simply initializing an int....
template <class T>
class templateClass {
templateClass() {};
[Code]....
My real code would only compile is I add the myData constructor:
myData () {};
and gdb confirmed that it is this constructor that get called, even with dummy(4).
View 4 Replies
View Related
Sep 18, 2013
How can a member function in my derived class call the same function from its base class?
View 1 Replies
View Related
Jul 6, 2014
error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)
Heres the code:
#include<iostream.h>
#include<conio.h>
void main() {
void sort(int,int);
clrscr();
[Code] .....
View 11 Replies
View Related
Apr 3, 2014
I am making a program that allows you to add two big numbers that are larger then what int can handle together. I think I have done everything to accomplish this but when I try to instantiate the program I get a error Expression must have a class type.
Here is my main file that is supposed to instantiate the program.
Code: #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h>
#include "LargeIntegers.h"
using namespace std;
[code]....
View 10 Replies
View Related
Apr 25, 2014
Code:
returnType operatorOperatorSymbol (parameterList); // syntax for operator overloading
Class Fraction
public:
Fraction operator-(const Fraction& f1){
Fraction r;
return r;
}
Is this even syntactically correct? It gives me errors. Im just trying to compile it without errors. I think the function makes sense since its returning a type Class
View 2 Replies
View Related
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 1 Replies
View Related
Nov 19, 2014
I am getting the error on the implementation of my class name. The error is coming from my parkingControl.cpp 'ParkingControl parkingControlMenu;'. I have used this implementation fine before, but once I added a new main it stopped working. Below is my code.
parkingControl.h
#ifndef PARKINGCONTROL_H_INCLUDED
#define PARKINGCONTROL_H_INCLUDED
#include <iostream>
[Code]....
View 2 Replies
View Related
Apr 6, 2015
I have two classes declared as below
#include<iostream>
using namespace std;
Class Node
{
[Code].....
View 4 Replies
View Related
Jul 3, 2013
I am trying to use a class Student and declare it as a list type. I can pushback but without changing the List.h or Node.h how can I print the data in list2?
Node.h
#ifndef NODE_H
#defineNODE_H
#include <string>
[Code].....
View 6 Replies
View Related
Oct 2, 2013
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
class houseinfo{
private:
string name;
string address;
[Code] .....
View 2 Replies
View Related
Apr 15, 2015
I'm trying to learn recursion, and I'm using a simple array to experiment with it, but I have a couple of annoying errors that I don't understand why they're there. Here's the code:
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int largest(const int arr[], int lowerIndex, int upperIndex) {
int max;
[code]....
Now try to print the array backwards:
//Use a recursive algorithm to find the largest element in arr:
int largest(arr[], lowerIndex, upperIndex);//error: expected an expression
return 0;
}
View 14 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
Aug 16, 2014
I am programming a 2-D platformer video game. The stages are composed of an array (really a vector) of 16x16 px^2 tiles. I have defined a base class "Tile" and several derived classes, e.g., "Ramp", "Door", etc., which have their own attributes. The idea is that upon entering a room, the program will load all of the necessary tile data for that room into a vector. So, I have a vector that looks like: vector <Tile*> room_tiles, and resize it based on the total number of tiles in the room: room_tiles.resize(Tile_Count). I then want to read in certain info from the data file containing all of the tile information for that room. For example, if the data file says Tile 5 should be a ramp, I want to change the 5th element of the room_tiles vector to the derived ramp class. This is really where I'm having trouble. I've worked with vectors of base and derived classes before, but those were always of indeterminate size and I always used something like: (Vector).push_back(new DerivedClass()) to specify the derived class of that element. The problem is that that method only seems to work if you are appending elements to the end of a vector.
how I can do this?
View 7 Replies
View Related
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
Feb 4, 2014
I'm trying to implement my own Stack class, for a generic data type. Here is what I have so far, but I'm having problems compiling the code:
Stack.h:
#ifndef STACK_H
#define STACK_H
#include <vector>
template< typename T >
class Stack {
[Code] .....
View 5 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
Jun 19, 2014
I've come across an interesting question involving a fixed-point arithmetic class.
Suppose I've got a template that implements a fixed-point quantity. It has two characteristics: width and number of fraction bits:
Code:
template <typename RAWTYPE, unsigned int FRACBITS>
class Fixed
{
....
};
So if I want a 32-bit value with 12 bits of fraction I can declare:
Code:
Fixed<int32_t, 12> x;
Suppose I've implemented a freestanding operator+() for fixed values, and I want to be able to add different types together:
Code:
template <typename RAWTYPE1, unsigned int FRACBITS1, typename RAWTYPE2, unsigned int FRACBITS2>
???? operator+(Fixed<RAWTYPE1, FRACBITS1> lhs, Fixed<RAWTYPE2, FRACBITS2> rhs)
{
???
}
What is the result type? Obviously, it's up to me to decide this. As reference, consider the type promotion rules for native types:
Code:
short a;
int b;
int result = a + b; In this case, the short value is promoted to the int value, and the addition happens on int.
It would seem a similar rule (go to the wider type) would be appropriate for fixed point. But there is another dimension to the problem, which is the number of fraction bits. Should you go to the wider type? Or the most precise type? Should you endeavor to minimize the number of bits which are discarded? What's the most intuitive rule?
View 10 Replies
View Related
Feb 4, 2015
For example I want to get the type of std::vector<>::size_type without specifying a template argument.
Here's what I want to do:
std::vector<>::size_type x{5};
Is there any way this can be done?
View 4 Replies
View Related
Jul 18, 2013
I am trying out a technique for a singleton class:
// access controlled singleton, accessed through function "instance()"
// singleton is constructed in this function
// so that constructor and destructor will be used
class single {
// private constructor/destructor
[Code] .....
Playing around with the code in main(), I am having trouble with auto:
single& s = single::instance(); // works fine
auto a = single::instance(); // error ~single() is private
When I make the destructor public, the output of the program is:
ctor
dtor
dtor
So I fixed this by typing auto&. I'm still confused though, why wouldn't auto know I am returning a reference?
View 2 Replies
View Related
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