Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I've got this error "expected ')' before '*' token" and i don't get why:
This is my EventController.h code
#ifndef EVENTCONTROLLER_H_
#define EVENTCONTROLLER_H_
#include <iostream>
#include "EventModel.h"
#include "UserModel.h"
using namespace std;
#include <vector>
#include <stdexcept>
#include "Observer.h"
class EventController{
public:
EventController(EventModel *eventModel, UserModel *userModel);
virtual ~EventController();
void EventDoneUndone(bool& eventcurrentstate);
void addPerson2Event(UserModel *userModel, EventModel *eventModel);
void Update();
private:
EventModel *eventModel;
UserModel *userModel;
};
#endif /* EVENTCONTROLLER_H_ */
And this is my EventController.cpp where i get the error
#include "EventController.h"
#include <iostream>
#include "EventModel.h"
#include "UserModel.h"
EventController(eventModel *eventModel, userModel *userModel){ **HERE I GET THE ERROR**
this->eventModel = eventModel;
this->userModel = userModel;
// eventModel->attach();
// userModel->attach();
}
EventController::~EventController() {
// TODO Auto-generated destructor stub
}
void eventDoneUndone(EventModel eventModel1){
eventModel1.toggleState();
}
void addPerson2Event(UserModel userModel1, EventModel eventModel1) {
eventModel1.setPerson2Event(userModel1);
}
void EventController::Update(){ //maniera Pull Observer myObs
cout << "C'è stato un Update su";
}
Hope you guys can help me, i've already try to figure it out looking for solution in others guys problems but i failed.
[1] https://imgur.com/a/oXR8y
Did you mean:
EventController::EventController(EventModel *eventModel, UserModel *userModel)
// ^^^^^^^^^^^^^^^^^ ^ ^
?
The signature in your .cpp file is not the same as the one in your header.
EventController(EventModel *eventModel, UserModel *userModel) //Header
EventController(eventModel *eventModel, userModel *userModel) //Source
You're using CamelCase in your Header for EventModel and UserModel in the header, and in your source you're just writing lowercase.
Also You forgot to add EventController:: to your constructor and other methods in your source file.
I think you want use the constructor. So code have to be like this :
EventController::EventController(eventModel *eventModel, userModel *userModel){
this->eventModel = eventModel;
this->userModel = userModel;
// eventModel->attach();
// userModel->attach();
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So I have test.h which contains:
#ifndef TEST_H_
#define TEST_H_
class test {
public:
int value;
};
#endif /* TEST_H_ */
and my main.cpp:
#include "test.h"
class Magic {
test x;
x.value = 2; // Syntax error
};
int main () {
test y;
y.value = 2; // Works fine
return 0;
}
Why is this happening?
Assigning values like that is not valid syntax in a class definition in c++. The error has nothing to do with headers or whatever. Try putting everything in a single file and you will see the same behavior.
If you want to have default initialization of x.value to 2 for each instance of Magic define this in the constructor of Magic:
class Magic {
test x;
Magic() {
x.value = 2;
}
};
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm getting the following errors:
C:\Users\James\cavewhere\dewalls\src\unit.cpp:6: error: C2511: 'dewalls::Unit::Unit(QString,dewalls::UnitType *)' : overloaded member function not found in 'dewalls::Unit'
C:\Users\James\cavewhere\dewalls\src\unit.cpp:9: error: C2550: 'dewalls::Unit::{ctor}' : constructor initializer lists are only allowed on constructor definitions
unit.h:
#ifndef UNIT_H
#define UNIT_H
class UnitType;
#include <QString>
namespace dewalls {
class Unit
{
public:
Unit(QString name, UnitType *type);
private:
QString _name;
UnitType *_type;
};
}
#endif // UNIT_H
unit.cpp:
#include "unit.h"
#include "unittype.h"
namespace dewalls {
Unit::Unit(QString name, UnitType *type) :
_name(name),
_type(type)
{
}
}
What for the love of god am I doing wrong?
Looks like UnitType should be in your namespace too
namespace dewalls {
class UnitType;
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm new to C++ and stuck in a problem with an Error, called
"Semantic Issue: Redefinition of 'B' cB.h".
I have two classes, A and B, where cA should handle an Object of cB by reference and one friend function of cA, fExample. This is what the code looks like:
.h file cA:
#include "cB.h"
class A{
int val1, val2;
public:
friend void fExample(int, cB &);
};
.h file cB:
class B{
int val1, val2;
public:
void set_val1(int);
};
.cpp file cB:
#include <iostream>
#include "cB.h"
using namespace std;
void B::set_val1(int tVal){
val1 = tVal;
}
For me, it seems there is no way of working with the cB-object by reference with a friend function of cA. I would know some workarounds, but that's not my intention, I want to learn how to handle this problem the right way.
So thanks in advance for helping!
This type of error often happen due to missing include guards. The Simplest way is:
#ifndef HEADER_NAME
#define HEADER_NAME
You may also use #pragma once
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have written a class:
CVerifObj.hpp:
#pragma once
#include <vector>
class VerifObj
{
private:
cv::Mat m_image;
PointVector m_plateContour;
std::string m_imageName;
public:
VerifObj(const fs::path& imgNameIn);
~VerifObj();
cv::Mat getImage() const;
std::string getImageName() const;
PointVector getPlateContour() const;
};
typedef std::vector< VerifObj > VerifObjVector;
That has implementation and that is used as a type of another function in another class that includes its header:
MyCls.hpp:
#pragma once
#include "CVerifObj.hpp"
class MyCls
{
public:
MyCls();
~MyCls();
static VerifObjVector foo(); // error is here
};
The problem I get is that it is not recognized:
/home/sop/proj/CMyCls.hpp:52:2: error: ‘VerifObjVector’ does not name a type
I have added it in the CMake file too. Why is this happening?
You haven't included the std::vector definition:
#include <vector>
You're probably including MyCls.hpp in CVerifObj.hpp, directly or indirectly, which leads to a circular include. This can cause issues (undefined types).
Remove circular includes by using forward declarations.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I must be overlooking something simple but I have so much to do in so little time that I might just be overworked. Anyway, here's where I'm getting the error.
#include<iostream>
#include<algorithm>
#ifndef Numbers
#define Numbers
class Numbers{
public:
Numbers(){capacity=5; used=0; data = new unsigned long[capacity];}
It's simply a constructor for the class Numbers. The private area of the class is as follows.
private:
unsigned long *data;
std::size_t used;
std::size_t capacity;
};
Again, it's probably something simple that I just can't see and I'm sure others run into the problem as well.
EDIT: error is as follows
numbers.h:9:11: error: expected unqualified-id before ')' token
Numbers(){capacity=5; used=0; data = new unsigned long[capacity];}
^
Run through the preprocessor, this:
#ifndef Numbers
#define Numbers
class Numbers{
public:
Numbers(){capacity=5; used=0; data = new unsigned long[capacity];}
becomes this :
class {
public:
() {capacity=5; used=0; data = new unsigned long[capacity];}
Your class name is the same as your include-guard fencepost macro. Since Numbers will be replaced with.. nothing.. you get no class name, nor constructor name. Don't do that.
Try:
#ifndef MYAPP_NUMBERS_H
#define MYAPP_NUMBERS_H
#include <iostream>
#include <algorithm>
class Numbers
{
public:
Numbers()
{
capacity=5;
used=0;
data = new unsigned long[capacity];
}
...etc...