When I try to compile this code I get these Errors:
Error 1 error C2061: syntax error : identifier 'stammdaten'
Error 2 error C2660: 'Test_Lohnab::Gehaltsrechner' : function does not take 1 arguments
Error 3 error C2511: 'int Test_Lohnab::Gehaltsrechner(stammdaten &)' : overloaded member function not found in 'Test_Lohnab'
It would be a big help, if someone could explain me what i did wrong.
This is my code:
//Test_Lohnab.h
#pragma once
#include <iostream>
#include <string>
class Test_Lohnab
{
public:
Test_Lohnab();
~Test_Lohnab();
int Gehaltsrechner(stammdaten &st);//, abrechnung &ab);
}
class stammdaten
{
public:
std::string name;
std::string strasse;
std::string ort;
….
public:
stammdaten();
~stammdaten();
stammdaten(std::string n, std::string s, std::string o, int st, int fa, int k, int a, double z, double kver, double pk, int mi, int pv, int os, int ps, int ki, double geb,
double jf, double jh, int G_c, int G_a_c, int r_c, int A_L_c, double U_1, double U_2, double bb_g);
}
//Test_Lohnab.cpp
#include "Test_Lohnab.h"
#include <iostream>
Test_Lohnab::Test_Lohnab()
{
}
Test_Lohnab::~Test_Lohnab()
{
}
stammdaten::stammdaten()
{
}
stammdaten::stammdaten(std::string n, std::string s, std::string o, int st, int fa, int k, int a, double z, double kver, double pk, int mi, int pv, int os, int ps, int ki, double geb,
double jf, double jh, int G_c, int G_a_c, int r_c, int A_L_c, double U_1, double U_2, double bb_g)
: name(n), strasse(s), ort(o), stkl(st), f(fa), krv(k), abv(a), zkf(z), kv(kver), pkpv(pk), mitag(mi), pvz(pv), ost(os), pvs(ps), kist(ki), gebjahr(geb), jfreib(jf), jhinzu(jh),
Gleitzone_check(G_c), Gleitzone_alt_check(G_a_c), rente_check(r_c), AN_Lst_check(A_L_c), U1(U_1), U2(U_2), bbg(bb_g)
{
}
int main()
{
system("PAUSE");
stammdaten Personstamm1{ "Klaus Müller", "Parkstrasse 12", "78578 Monopoly", 1, 1000, 1, 1, 0, 15.5, 0.0, 0, 1, 0, 0, 9, 1982, 0, 0, 0, 0, 0, 0, 1.7, 0.38, 0 };
/**/
Test_Lohnab Ablauf;
Ablauf.Gehaltsrechner(Personstamm1); //, Abrechnung1);
system("PAUSE");
/**/
}
int Test_Lohnab::Gehaltsrechner(stammdaten &Test1)//, abrechnung &Abrech1)
{
}
Your classes Test_Lohnab function int Gehaltsrechner needs an object of the type stammdaten which the compiler does not yet know about because it is defined afterwards. You can use forward declaration to inform him about it. Simply add the following line after your includes
class stammdaten;
Related
I'm doing a c++ app and I'm having some troubles while doing it and I can't fix the error.
I have a class ratinmaze that I'd like to use in the main class, but i get a lot of errors..
ratinmaze.h
#ifndef RATINMAZE_H
#define RATINMAZE_H
#include <iostream>
class ratinmaze
{
public:
ratinmaze();
int [5][5] solution; //error
virtual ~ratinmaze();
ratinmaze(int N);
void solveMaze(int [][5] maze, int N);
bool findPath(int [][5] maze, int x, int y, int N, std::string direction);
bool isSafeToGo(int [][5] maze, int x, int y, int N);
void print(int [][5] solution, int N);
void print(int [][5] solution, int N);
protected:
private:
std::string direction;
int N;
int y;
int x;
};
#endif // RATINMAZE_H
main.cpp
#include <iostream>
#include "ratinmaze.h"
using namespace std;
int main()
{
int N = 5;
int[5][5] maze = {{ 1, 0, 1, 1,1 },
{ 1, 1, 1, 0,1 },
{ 0, 0,0, 1, 1 },
{ 0, 0, 0, 1,0 },
{ 0, 0,0, 1, 1 }};
ratinmaze r = new ratinmaze(N);
r.solveMaze(maze, N);
return 0;
}
I get the error in the first line :
expected unqualifie-id before '[' token and in the following i get
"error : expected ',' or '...' before 'maze'
If u guys could help me I would be really appreciated!
#update
I figured out that I was not creating the right way my arrays but I have an error here on my main : ratinmaze r = new ratinmaze(N);
the error is :
invalid conversion from 'ratinmaze*' to 'int' [-fpermissive]
Any idea ?
Arrays in C++ are declared with the square brackets after the variable name, like so:
int solution[5][5];
When I run this code and create an instance of cylinderType by passing four parameters, debugger shows the height I want but, radius=x=y=0. So when I call method printVolume() on this object, it displays '0'.
Am I missing something important with inheritance?
Thank you~
#include <iostream>
using namespace std;
class circleType
{
public:
circleType();
circleType(double r);
double getArea() const;
private:
double radius;
};
class cylinderType : public circleType
{
public:
cylinderType(double h, double r);
void printVolume() const;
private:
double height;
};
int main()
{
cylinderType cylinderA(2, 4);
cylinderA.printVolume();
return 0;
};
circleType::circleType()
{
radius = 0;
};
circleType::circleType(double r)
{
radius = r;
};
double circleType::getArea() const
{
return (3.14 * radius* radius);
};
cylinderType::cylinderType(double h, double r)
{
circleType::circleType(r);
height = h;
};
void cylinderType::printVolume() const
{
cout << (circleType::getArea() * height);
};
I've a structure DutPlayerArrayElement defined in following lines:
namespace Common
{
namespace Constants {
const int MaxNumberOfIPAddresses = 10;
const int NumberOFRFOutputs = 100;
const int NumberOfPlayers = 100;
const int SignalFileNameSize = 30;
}
enum AntennaType
{
Omni = 0,
Directive,
Custom,
InvalidAntenna
};
enum ModulationID
{
CW = 0,
SSB,
LSB,
AM,
FM,
WFM,
DVBT
};
enum SigFileID
{
SIG_FILE_ID_ARB12 = 1,
SIG_FILE_ID_ARB16,
SIG_FILE_ID_WAV,
SIG_FILE_ID_TXT
};
typedef struct
{
//Basic
double dLatitude;
double dLongitude;
double dAltitude;
double dHeading;
float fNorthSudVelocity;
float fEastOvestVelocity;
float fVerticalVelocity;
unsigned int uiIsValid;
bool bIsDestroyed;
bool bTxIsOn;
ModulationID xModulationID;
SigFileID xSigFileType ;
char cSigFileName[128];
bool bLoopPlayback ;
char cAntennaTableFile[128];
bool bUseAntGainFactor;
double dAntGainFactor;
double dAntennaOrientation;
double dCarrierFrequency;
bool bTxIsLOS;
double dPwr;
double dAzimuth;
double dElevation;
double dDistance;
char cEntityName[128];
//char cModulation[2];
}PlayerArrayElement;
typedef struct
{
//Basic
double dLatitude;
double dLongitude;
double dAltitude;
double dHeading;
float fNorthSudVelocity;
float fEastOvestVelocity;
float fVerticalVelocity;
bool bIsDestroyed;
unsigned int uiNumAssignedRFOut;
bool bIsSync;
unsigned int uiNumRFOutXIP;
int iAssignedRFOut[Constants::NumberOFRFOutputs];
unsigned int uiRfGenCount;
int iIpAddress[Constants::MaxNumberOfIPAddresses];
unsigned int xPort[10];
double xCarrierFrequency[10];
//AntennaType xAntennatype;
char cAntennaTableFile[128];
bool bUseAntGainFactor;
double dAntGainFactor;
double dAntennaOrientation;
unsigned int uiNumOfPlayer;
PlayerArrayElement xScenarioPlayer[Constants::NumberOfPlayers];
char cEntityName[128];
unsigned int uiIsValid;
bool simIsRunning;
} DutPlayerArrayElement;
typedef std::vector<DutPlayerArrayElement> DutPlayers;
}
I also define a typedef std::vector<DutPlayerArrayElement> DutPlayers;
In a Visual studio 2008 library, I declare a class with this vector as member:
class COM_API MyClass
{
public:
SimComintManager();
~SimComintManager() ;
bool init();
void runme();
private:
void setup();
private:
// ....
Common::DutPlayers m_xDutPlayers;
// other structures...
};
in runme method:
void MyClass::runme()
{
while(m_bScenarioIsRunning)
{
if(m_uiIterationCount == 0)
{
m_pGen->setRfOutState(0, ON);
}
else
{
//aggiornare RF scenario in base a SHM attuale
m_xDutPlayers.clear() ;
m_xShmReader.getData(m_xDutPlayers) ;
}
}
}
ShmReader is a class defined in another library, that uses the same .h file in which vector is defined:
bool Reader::getData( Common::DutPlayers& xDutVector)
{
Common::DutPlayerArrayElement xEntityArrayElement;
for(int i = 0; i < m_iNumberOfEntities; i++)
{
xEntityArrayElement = m_pxPlayerShmVector->getValue(i);
if(xEntityArrayElement.uiIsValid == 1)
m_bSimulationState = xEntityArrayElement.simIsRunning;
xDutVector.push_back(xEntityArrayElement);
}
return true;
}
When I call xDutVector.push_back(xEntityArrayElement); I've an error and program crashes. Visual studio says Microsoft Visual Studio C Runtime Library has detected a fatal error in program.exe and when I click Break button the callstack is in row 161 of vector.h, the _SCL_SECURE_VALIDATE_RANGE row of this piece of code:
_Myt& operator+=(difference_type _Off)
{ // increment by integer
_SCL_SECURE_VALIDATE(this->_Has_container());
_SCL_SECURE_VALIDATE_RANGE(
_Myptr + _Off <= ((_Myvec *)(this->_Getmycont()))->_Mylast &&
_Myptr + _Off >= ((_Myvec *)(this->_Getmycont()))->_Myfirst);
_Myptr += _Off;
return (*this);
}
I've googled a bit and I've found this error regarding iterator erasing, but nothing regarding the push_back. What I'm doing wrong and how can I use push_back correctly?
I am trying to write a class and I finally got it to compile, but visual studio still shows there are errors (with a red line).
The problem is at (I wrote #problem here# around the places where visual studio draws a red line):
1. const priority_queue<int,vector<int>,greater<int> #># * CM::getHeavyHitters() {
2. return & #heavyHitters# ;
3. }
And it says:
"Error: expected an identifier" (at the first line)
"Error: identifier "heavyHitters" is undefined" (at the second line)
The first problem I don't understand at all. The second one I don't understand because heavyHitters is a a member of CM and I included CM.
BTW, I tried to build. It didn't fix the problem.
Thanks!!!
The whole code is here:
Count-Min Sketch.cpp
#include "Count-Min Sketch.h"
CM::CM(double eps, double del) {
}
void CM::update(int i, int long unsigned c) {
}
int long unsigned CM::point(int i) {
int min = count[0][calcHash(0,i)];
return min;
}
const priority_queue<int,vector<int>,greater<int>>* CM::getHeavyHitters() {
return &heavyHitters;
}
CM::CM(const CM &) {
}
CM::~CM() {
}
int CM::calcHash(int hashNum, int inpt) {
int a = hashFunc[hashNum][0];
int b = hashFunc[hashNum][1];
return ((a*inpt+b) %p) %w;
}
bool CM::isPrime(int a) {
bool boo = true;
return boo;
}
int CM::gePrime(int n) {
int ge = 2;
return ge;
}
Count-Min Sketch.h
#pragma once
#ifndef _CM_H
#define _CM_H
using namespace std;
#include <queue>
class CM {
private:
// d = ceiling(log(3,1/del)), w = ceiling(3/eps)
int d,w,p;
// [d][w]
int long unsigned *(*count);
// [d][2]
int *(hashFunc[2]);
// initialized to 0. norm = sum(ci)
int long unsigned norm;
// Min heap
priority_queue<int,vector<int>,greater<int>> heavyHitters;
// ((ax+b)mod p)mod w
int calcHash(int hashNum, int inpt);
// Is a a prime number
bool isPrime(int a);
// Find a prime >= n
int gePrime(int n);
public:
// Constructor
CM(double eps, double del);
// count[j,hj(i)]+=c for 0<=j<d, norm+=c, heap update & check
void update(int i, int long unsigned c);
// Point query ai = minjcount[j,hj(i)]
int long unsigned point(int i);
const priority_queue<int,vector<int>,greater<int>>* getHeavyHitters();
// Copy constructor
CM(const CM &);
// Destructor
~CM();
};
#endif // _CM_H
>> is a single token, the right-shift (or extraction) operator. Some compilers don't recognize it correctly in nested template specialization. You have to put a space between the two angle brackets like this:
Type<specType<nestedSpecType> > ident;
^^^
highInterestChecking Header:
#ifndef H_highInterestChecking
#define H_highInterestChecking
#include "noservicechargechecking.h"
#include <string>
class highInterestChecking: public noServiceChargeChecking
{
public:
highInterestChecking(std::string =" ",int = 0, double = 0.00, double = 0.00, double = 0.00);
};
#endif
highInterestChecking cpp:
#include "highInterestChecking.h"
using std::string;
highInterestChecking::highInterestChecking(string name, int acct, double bal, int numCheck, double min, double i)
{
bankAccount::setAcctOwnersName(name);
bankAccount::setAcctNum(acct);
bankAccount::setBalance(bal);
checkingAccount::setChecks(numCheck);
noServiceChargeChecking::setMinBalance(min);
noServiceChargeChecking::setInterestRate(i);
}
I have the error "No instance of overloaded function." under the constructor name highInterestChecking in the cpp file not sure what is causing it ive looked at it for a while now can't seem to find an error. maybe someone will help?
In the header you have:
highInterestChecking(std::string =" ",int = 0, double = 0.00, double = 0.00, double = 0.00);
Which takes 5 arguments, In the source file you have:
highInterestChecking::highInterestChecking(string name, int acct, double bal, int numCheck, double min, double i)
^^^^^^^^^^^
which takes 6 arguments. It seems like int numCheck does not match the header signature.
You have this constructor in the class declaration:
highInterestChecking(std::string =" ",int = 0, double = 0.00, double = 0.00, double = 0.00);
and this one in the class definition:
highInterestChecking::highInterestChecking(string name, int acct, double bal, int numCheck, double min, double i)
The parameter types from both parameter lists must match.
highInterestChecking::highInterestChecking(string name, int acct,
double bal, int numCheck, double min, double i)
//^^^
does not exist in your class's header file, header file has 5 parameters, but you have 6 in cpp file, parameter type seems mismatched,