Am I compiling in the wrong way? - c++

So I've got this RPN calculator project and I will try to post all the code for it; would I just run "C++ dc.cpp"? I get returned an error even though I know someone else has compiled it correctly. How do I compile this?
dc.cpp
#include <iostream>
#include "stack.h"
#include <string>
#include "dsexceptions.h"
using namespace std;
bool IsOperator(char op);
int calculate(char op, int operand1, int operand2);
int main() {
string input;
Stack<int> dc;
while (getline(cin, input))
{
for (int i = 0; i<input.length(); i++)
{
if (input[i] == ' ')
continue;
else if (IsOperator(input[i]))
{
try {
int operand2 = dc.top();
dc.pop();
int operand1 = dc.top();
dc.pop();
int result = calculate(input[i], operand1, operand2);
dc.push(result);
}
catch (Underflow e) {
cout << "No elements in stack";
}
catch (Overflow e) {
cout << "Stack full. Can't insert more";
}
catch (DivisionByZero e) {
cout << "Please choose some other value for division except 0";
}
catch (InvalidOperator e) {
cout << "The operator you choose is invalid";
}
}
else if (isdigit(input[i]))
{
int operand = 0;
while (i<input.length() && isdigit(input[i]))
{
operand = (operand * 10) + (input[i] - '0');
i++;
}
i--;
if (i && input[i - 1] == '_')
operand *= -1;
try {
dc.push(operand);
}
catch (Overflow e) {
cout << "Stack full. Can't insert more";
}
}
else if (input[i] == 'p') {
try {
cout << dc.top() << endl;
}
catch (Underflow e) {
cout << "No elements in stack";
}
}
else if (input[i] == 'n') {
try {
cout << dc.top();
}
catch (Underflow e) {
cout << "No elements in stack";
}
}
else if (input[i] == 'f') {
for (Stack <int> dump = dc; !dump.isEmpty(); dump.pop()) {
try {
cout << dump.top() << " ";
}
catch (Underflow e) {
cout << "No elements in stack";
}
}
cout << endl;
}
else if (input[i] == 'c') {
while (!dc.isEmpty())
dc.pop();
}
else if (input[i] == 'd') {
try {
dc.push(dc.top());
}
catch (Overflow e) {
cout << "Stack full. Can't insert more";
}
catch (Underflow e) {
cout << "No elements in stack";
}
}
else if (input[i] == 'r') {
try {
int x = dc.top();
dc.pop();
int y = dc.top();
dc.pop();
dc.push(x);
dc.push(y);
}
catch (Overflow e) {
cout << "Stack full. Can't insert more";
}
catch (Underflow e) {
cout << "No elements in stack";
}
}
}
}
return 0;
}
bool IsOperator(char op)
{
if (op == '+' || op == '-' || op == '*' || op == '/' || op == '%')
{
return true;
}
else
{
return false;
}
}
int calculate(char op, int operand1, int operand2)
{
if (op == '+')
{
return operand1 + operand2;
}
else if (op == '-')
{
return operand1 - operand2;
}
else if (op == '*')
{
return operand1 * operand2;
}
else if (op == '/')
{
return operand1 / operand2;
if (operand2 == 0)
{
throw DivisionByZero();
}
}
else if (op == '%')
{
return operand1 % operand2;
}
else {
throw InvalidOperator();
}
}
dsexceptions.h
#ifndef _DSEXCEPTIONS_H_
#define _DSEXCEPTIONS_H_
#include <iostream>
class Underflow : public std::runtime_error
{
public:
Underflow(std::string const& error)
: std::runtime_error(error) {}
Underflow()
:std::runtime_error("Underflow Exception") {}
};
class Overflow : public std::runtime_error
{
public:
Overflow(std::string const& error)
: std::runtime_error(error) {}
Overflow()
:std::runtime_error("Overflow Exception") {}
};
class InvalidOperator : public std::runtime_error
{
public:
InvalidOperator(std::string const& error)
: std::runtime_error(error) {}
InvalidOperator()
:std::runtime_error("Invalid Exception") {}
};
class OutOfMemory : public std::runtime_error
{
public:
OutOfMemory(std::string const& error)
: std::runtime_error(error) {}
OutOfMemory()
:std::runtime_error("Out Of Memory Exception") {}
};
class BadIterator : public std::runtime_error
{
public:
BadIterator(std::string const& error)
: std::runtime_error(error) {}
BadIterator()
:std::runtime_error("Bad Iterator Exception") {}
};
class DataError : public std::runtime_error
{
public:
DataError(std::string const& error)
: std::runtime_error(error) {}
DataError()
:std::runtime_error("Data Error Exception") {}
};
class DivisionByZero : public std::runtime_error
{
public:
DivisionByZero(std::string const& error)
: std::runtime_error(error) {}
DivisionByZero()
:std::runtime_error("Division By Zero Exception") {}
};
#endif
stack.cpp
#include "dsexceptions.h"
#include "stack.h"
/**
* Construct the stack.
*/
template <class Object>
Stack<Object>::Stack(int aCapacity)
{
topOfStack = -1;
capacity = aCapacity;
theArray.resize(aCapacity);
}
/**
* Test if the stack is logically empty.
* Return true if empty, false otherwise.
*/
template <class Object>
bool Stack<Object>::isEmpty() const
{
return topOfStack == -1;
}
/**
* Test if the stack is logically full.
* Return true if full, false otherwise.
*/
template <class Object>
bool Stack<Object>::isFull() const
{
return topOfStack == capacity - 1;
}
/**
* Make the stack logically empty.
*/
template <class Object>
void Stack<Object>::makeEmpty()
{
topOfStack = -1;
}
/**
* Get the most recently inserted item in the stack.
* Does not alter the stack.
* Return the most recently inserted item in the stack.
* Exception Underflow if stack is already empty.
*/
template <class Object>
const Object & Stack<Object>::top() const
{
if (isEmpty())
throw Underflow();
return theArray[topOfStack];
}
/**
* Remove the most recently inserted item from the stack.
* Exception Underflow if stack is already empty.
*/
template <class Object>
void Stack<Object>::pop()
{
if (isEmpty())
throw Underflow();
topOfStack--;
}
/**
* Insert x into the stack, if not already full.
* Exception Overflow if stack is already full.
*/
template <class Object>
void Stack<Object>::push(const Object & x)
{
if (isFull())
throw Overflow();
theArray[++topOfStack] = x;
}
/**
* Return and remove most recently inserted item from the stack.
* Return most recently inserted item.
* Exception Underflow if stack is already empty.
*/
template <class Object>
Object Stack<Object>::topAndPop()
{
if (isEmpty())
throw Underflow();
return theArray[topOfStack--];
}
/* int main()
{
cout << "testing stack class" << endl;
Stack<int> dc(100);
cout << " stack class init" << endl;
dc.push(10);
dc.pop();
cout << "done testing stack class" << endl;
}*/
My compiler returns these errors when I run "c++ dc.cpp". I have to just be compiling it incorrectly, right?:
In file included from stack.cpp:1:
dsexceptions.h:8: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Underflow::Underflow(const std::string&)’:
dsexceptions.h:11: error: expected class-name before ‘(’ token
dsexceptions.h:11: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Underflow::Underflow()’:
dsexceptions.h:14: error: expected class-name before ‘(’ token
dsexceptions.h:14: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:18: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Overflow::Overflow(const std::string&)’:
dsexceptions.h:22: error: expected class-name before ‘(’ token
dsexceptions.h:22: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Overflow::Overflow()’:
dsexceptions.h:25: error: expected class-name before ‘(’ token
dsexceptions.h:25: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:29: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator(const std::string&)’:
dsexceptions.h:33: error: expected class-name before ‘(’ token
dsexceptions.h:33: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator()’:
dsexceptions.h:36: error: expected class-name before ‘(’ token
dsexceptions.h:36: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:42: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory(const std::string&)’:
dsexceptions.h:46: error: expected class-name before ‘(’ token
dsexceptions.h:46: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory()’:
dsexceptions.h:49: error: expected class-name before ‘(’ token
dsexceptions.h:49: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:53: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator(const std::string&)’:
dsexceptions.h:57: error: expected class-name before ‘(’ token
dsexceptions.h:57: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator()’:
dsexceptions.h:60: error: expected class-name before ‘(’ token
dsexceptions.h:60: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:64: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DataError::DataError(const std::string&)’:
dsexceptions.h:68: error: expected class-name before ‘(’ token
dsexceptions.h:68: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DataError::DataError()’:
dsexceptions.h:71: error: expected class-name before ‘(’ token
dsexceptions.h:71: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:75: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero(const std::string&)’:
dsexceptions.h:79: error: expected class-name before ‘(’ token
dsexceptions.h:79: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero()’:
dsexceptions.h:82: error: expected class-name before ‘(’ token
dsexceptions.h:82: error: expected ‘{’ before ‘(’ token
In file included from stack.cpp:2:
stack.h: At global scope:
stack.h:1: error: expected constructor, destructor, or type conversion before ‘<’ token
stack.h:34: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:34: error: expected ‘;’ before ‘<’ token
stack.h:36: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:36: error: expected ‘;’ before ‘<’ token
stack.cpp: In constructor ‘Stack<Object>::Stack(int)’:
stack.cpp:11: error: ‘theArray’ was not declared in this scope
stack.cpp: In member function ‘const Object& Stack<Object>::top() const’:
stack.cpp:54: error: ‘theArray’ was not declared in this scope
stack.cpp: In member function ‘void Stack<Object>::push(const Object&)’:
stack.cpp:78: error: ‘theArray’ was not declared in this scope
stack.cpp: In member function ‘Object Stack<Object>::topAndPop()’:
stack.cpp:91: error: ‘theArray’ was not declared in this scope
[jones_g#cobra Prog2]$ c++ dc.cpp
In file included from dc.cpp:2:
stack.h:1: error: expected constructor, destructor, or type conversion before ‘<’ token
stack.h:34: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:34: error: expected ‘;’ before ‘<’ token
stack.h:36: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:36: error: expected ‘;’ before ‘<’ token
In file included from dc.cpp:4:
dsexceptions.h:8: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Underflow::Underflow(const std::string&)’:
dsexceptions.h:11: error: expected class-name before ‘(’ token
dsexceptions.h:11: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Underflow::Underflow()’:
dsexceptions.h:14: error: expected class-name before ‘(’ token
dsexceptions.h:14: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:18: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Overflow::Overflow(const std::string&)’:
dsexceptions.h:22: error: expected class-name before ‘(’ token
dsexceptions.h:22: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Overflow::Overflow()’:
dsexceptions.h:25: error: expected class-name before ‘(’ token
dsexceptions.h:25: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:29: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator(const std::string&)’:
dsexceptions.h:33: error: expected class-name before ‘(’ token
dsexceptions.h:33: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator()’:
dsexceptions.h:36: error: expected class-name before ‘(’ token
dsexceptions.h:36: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:42: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory(const std::string&)’:
dsexceptions.h:46: error: expected class-name before ‘(’ token
dsexceptions.h:46: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory()’:
dsexceptions.h:49: error: expected class-name before ‘(’ token
dsexceptions.h:49: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:53: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator(const std::string&)’:
dsexceptions.h:57: error: expected class-name before ‘(’ token
dsexceptions.h:57: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator()’:
dsexceptions.h:60: error: expected class-name before ‘(’ token
dsexceptions.h:60: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:64: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DataError::DataError(const std::string&)’:
dsexceptions.h:68: error: expected class-name before ‘(’ token
dsexceptions.h:68: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DataError::DataError()’:
dsexceptions.h:71: error: expected class-name before ‘(’ token
dsexceptions.h:71: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:75: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero(const std::string&)’:
dsexceptions.h:79: error: expected class-name before ‘(’ token
dsexceptions.h:79: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero()’:
dsexceptions.h:82: error: expected class-name before ‘(’ token
dsexceptions.h:82: error: expected ‘{’ before ‘(’ token
[jones_g#cobra Prog2]$ c++ dc.cpp
In file included from dc.cpp:2:
stack.h:1: error: expected constructor, destructor, or type conversion before ‘<’ token
stack.h:34: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:34: error: expected ‘;’ before ‘<’ token
stack.h:36: error: ISO C++ forbids declaration of ‘vector’ with no type
stack.h:36: error: expected ‘;’ before ‘<’ token
In file included from dc.cpp:4:
dsexceptions.h:8: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Underflow::Underflow(const std::string&)’:
dsexceptions.h:11: error: expected class-name before ‘(’ token
dsexceptions.h:11: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Underflow::Underflow()’:
dsexceptions.h:14: error: expected class-name before ‘(’ token
dsexceptions.h:14: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:18: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘Overflow::Overflow(const std::string&)’:
dsexceptions.h:22: error: expected class-name before ‘(’ token
dsexceptions.h:22: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘Overflow::Overflow()’:
dsexceptions.h:25: error: expected class-name before ‘(’ token
dsexceptions.h:25: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:29: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator(const std::string&)’:
dsexceptions.h:33: error: expected class-name before ‘(’ token
dsexceptions.h:33: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘InvalidOperator::InvalidOperator()’:
dsexceptions.h:36: error: expected class-name before ‘(’ token
dsexceptions.h:36: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:42: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory(const std::string&)’:
dsexceptions.h:46: error: expected class-name before ‘(’ token
dsexceptions.h:46: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘OutOfMemory::OutOfMemory()’:
dsexceptions.h:49: error: expected class-name before ‘(’ token
dsexceptions.h:49: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:53: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator(const std::string&)’:
dsexceptions.h:57: error: expected class-name before ‘(’ token
dsexceptions.h:57: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘BadIterator::BadIterator()’:
dsexceptions.h:60: error: expected class-name before ‘(’ token
dsexceptions.h:60: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:64: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DataError::DataError(const std::string&)’:
dsexceptions.h:68: error: expected class-name before ‘(’ token
dsexceptions.h:68: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DataError::DataError()’:
dsexceptions.h:71: error: expected class-name before ‘(’ token
dsexceptions.h:71: error: expected ‘{’ before ‘(’ token
dsexceptions.h: At global scope:
dsexceptions.h:75: error: expected class-name before ‘{’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero(const std::string&)’:
dsexceptions.h:79: error: expected class-name before ‘(’ token
dsexceptions.h:79: error: expected ‘{’ before ‘(’ token
dsexceptions.h: In constructor ‘DivisionByZero::DivisionByZero()’:
dsexceptions.h:82: error: expected class-name before ‘(’ token
dsexceptions.h:82: error: expected ‘{’ before ‘(’ token

It looks like you are compiling it fine, but your code has errors, which your compiler is telling you about.
At the very least, add...
#include <stdexcept>
... to your dsexceptions.h file.
You might also need to add...
#include <vector>
... to your stack.h file.

You need to read the error message more carefully. Taking just the first message:
dsexceptions.h:8: error: expected class-name before ‘{’ token
You can see that the compiler doesn't recognise the token immediately preceding {. What's that token? Line 7 is
class Underflow : public std::runtime_error
Yes, you're using std::runtime_error, but haven't defined it. The fix, of course, is to #include <stdexcept> instead of the unnecessary #include <iostream>.
In your headers you should normally include any definitions that the header needs (and only what the header needs). If you don't, then you are likely to end up with very fragile code where headers fail as above if the code using them doesn't know the prerequisites. It's okay to include the standard library headers multiple times, and the same is true of any well-written library header.
There are tools, such as include-what-you-use (aka iwyu) to help analyse your source files for missing or unnecessary includes - you should certainly look to see if that might help you.

Related

Weird C++ error, unqualified ID, redeclaration

I want to create a project, I have 3 files, a test.cpp, something.h and a something.cpp. here they are:
test.cpp:
#include <bits/stdc++.h>
#define f cin
#define g cout
#include "something.h"
using namespace std;
int main(void)
{
int x;
register(x);
return 0;
}
something.h:
#ifndef __SOMETHING__H_
#define __SOMETHING__H_
#include <bits/stdc++.h>
void register(int x);
#endif
something.cpp:
#include "something.h"
void register(int x)
{
std::cout << x << '\n';
}
And here is the error I get:
In file included from test.cpp:4:0:
something.h:5:15: error: expected unqualified-id before ‘int’
void register(int x);
^~~
something.h:5:15: error: expected ‘)’ before ‘int’
test.cpp: In function ‘int main()’:
test.cpp:10:15: error: ISO C++ forbids declaration of ‘x’ with no type [-fpermissive]
register(x);
^
test.cpp:10:15: error: redeclaration of ‘int x’
test.cpp:9:9: note: ‘int x’ previously declared here
int x;
^
In file included from something.cpp:1:0:
something.h:5:15: error: expected unqualified-id before ‘int’
void register(int x);
^~~
something.h:5:15: error: expected ‘)’ before ‘int’
something.cpp:3:15: error: expected unqualified-id before ‘int’
void register(int x)
^~~
something.cpp:3:15: error: expected ‘)’ before ‘int’
Why does it tell me that I redefine x? When I just want to call register with it's value.
register is a reserved word in C++. Therefore, you have to give another (unreserved) name.
more information: Register keyword in C++ - Stack Overflow

variable ‘qglviewer::QGLVIEWER_EXPORT qglviewer::Constraint’ has initializer but incomplete type

I want to apply QGLViewer multiselect on 3d object viewed as Linear_cell_complex_for_bgl_combinatorial_map_helper from .off file
my project on GitHub here
it shows errors about using GLViewer/constraint.h as following :
/usr/include/QGLViewer/constraint.h:117:24: error: variable ‘qglviewer::QGLVIEWER_EXPORT qglviewer::Constraint’ has initializer but incomplete type
class QGLVIEWER_EXPORT Constraint
^~~~~~~~~~
/usr/include/QGLViewer/constraint.h:119:1: error: expected primary-expression before ‘public’
public:
^~~~~~
/usr/include/QGLViewer/constraint.h:119:1: error: expected ‘}’ before ‘public’
/usr/include/QGLViewer/constraint.h:118:1: note: to match this ‘{’
{
^
/usr/include/QGLViewer/constraint.h:119:1: error: expected ‘,’ or ‘;’ before ‘public’
public:
^~~~~~
/usr/include/QGLViewer/constraint.h:133:2: error: ‘virtual’ outside class declaration
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^~~~~~~
/usr/include/QGLViewer/constraint.h:133:36: error: variable or field ‘constrainTranslation’ declared void
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^~~
/usr/include/QGLViewer/constraint.h:133:36: error: ‘Vec’ was not declared in this scope
/usr/include/QGLViewer/constraint.h:133:36: note: suggested alternative:
In file included from /usr/local/include/CGAL/Qt/qglviewer.h:26,
from /usr/local/include/CGAL/Qt/Basic_viewer_qt.h:40,
from /usr/local/include/CGAL/draw_linear_cell_complex.h:24,
from ../Projects/CM2/mainwindow.h:13,
from ../Projects/CM2/main.cpp:2:
/usr/local/include/CGAL/Qt/vec.h:64:22: note: ‘CGAL::qglviewer::Vec’
class CGAL_QT_EXPORT Vec {
^~~
In file included from ../Projects/CM2/manipulatedframesetconstraint.h:3,
from ../Projects/CM2/mainwindow.h:36,
from ../Projects/CM2/main.cpp:2:
/usr/include/QGLViewer/constraint.h:133:41: error: ‘translation’ was not declared in this scope
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^~~~~~~~~~~
/usr/include/QGLViewer/constraint.h:133:41: note: suggested alternative: ‘QTranslator’
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^~~~~~~~~~~
QTranslator
/usr/include/QGLViewer/constraint.h:133:59: error: expected primary-expression before ‘*’ token
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^
/usr/include/QGLViewer/constraint.h:133:61: error: expected primary-expression before ‘const’
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
^~~~~
/usr/include/QGLViewer/constraint.h:142:2: error: ‘virtual’ outside class declaration
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^~~~~~~
/usr/include/QGLViewer/constraint.h:142:33: error: variable or field ‘constrainRotation’ declared void
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^~~~~~~~~~
/usr/include/QGLViewer/constraint.h:142:33: error: ‘Quaternion’ was not declared in this scope
/usr/include/QGLViewer/constraint.h:142:33: note: suggested alternative:
In file included from /usr/local/include/CGAL/Qt/camera.h:27,
from /usr/local/include/CGAL/Qt/qglviewer.h:27,
from /usr/local/include/CGAL/Qt/Basic_viewer_qt.h:40,
from /usr/local/include/CGAL/draw_linear_cell_complex.h:24,
from ../Projects/CM2/mainwindow.h:13,
from ../Projects/CM2/main.cpp:2:
/usr/local/include/CGAL/Qt/quaternion.h:69:22: note: ‘CGAL::qglviewer::Quaternion’
class CGAL_QT_EXPORT Quaternion {
^~~~~~~~~~
In file included from ../Projects/CM2/manipulatedframesetconstraint.h:3,
from ../Projects/CM2/mainwindow.h:36,
from ../Projects/CM2/main.cpp:2:
/usr/include/QGLViewer/constraint.h:142:45: error: ‘rotation’ was not declared in this scope
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^~~~~~~~
/usr/include/QGLViewer/constraint.h:142:45: note: suggested alternative: ‘QAction’
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^~~~~~~~
QAction
/usr/include/QGLViewer/constraint.h:142:60: error: expected primary-expression before ‘*’ token
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^
/usr/include/QGLViewer/constraint.h:142:62: error: expected primary-expression before ‘const’
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
^~~~~
/usr/include/QGLViewer/constraint.h:168:44: error: expected initializer before ‘:’ token
class QGLVIEWER_EXPORT AxisPlaneConstraint : public Constraint
^
/usr/include/QGLViewer/constraint.h:279:40: error: expected initializer before ‘:’ token
class QGLVIEWER_EXPORT LocalConstraint : public AxisPlaneConstraint
^
/usr/include/QGLViewer/constraint.h:299:40: error: expected initializer before ‘:’ token
class QGLVIEWER_EXPORT WorldConstraint : public AxisPlaneConstraint
^
/usr/include/QGLViewer/constraint.h:319:41: error: expected initializer before ‘:’ token
class QGLVIEWER_EXPORT CameraConstraint : public AxisPlaneConstraint
^
/usr/include/QGLViewer/constraint.h:336:1: error: expected declaration before ‘}’ token
} // namespace qglviewer
^
all errors were shown in Constraint.h which is already in QGLViewer , So I don't know what is the problem.
I appreciate any help , thanks
To summurize the resolution :
Use the include files from /usr/local/include/CGAL/Qt/QGLViewer and not from /usr/local/include/QGLViewer
In your code, use the types with the namespace CGAL::qglviewer:: and not only qglviewer::

How to fix expected primary-expression?

#include<iostream>
#include<memory>
class test{
public:
void print()
{
std::cout<<"test print"<<std::endl;
}
};
int main
{
std::auto_ptr<test> t1 (new test);
t1->print();
return 0;
}
I am getting following error:
$g++ 5.cpp --std=c++11
5.cpp:16:22: error: expected primary-expression before ‘t1’
std::auto_ptr<test> t1 (new test);
^
5.cpp:16:22: error: expected ‘}’ before ‘t1’
5.cpp:16:22: error: expected ‘,’ or ‘;’ before ‘t1’
5.cpp:17:2: error: ‘t1’ does not name a type
t1->print();
^
5.cpp:19:2: error: expected unqualified-id before ‘return’
return 0;
^
5.cpp:20:1: error: expected declaration before ‘}’ token
}
^
int main // <-- Notice anything ?
the problem is, that you forgot the parantheses in main.
int main { ...} // this is wrong!
but the right would be
int main() { ... }

Overloading prefix and postfix increment in class timer. Problems while debugging

I need to overload increment for class Timer. Members of my class are minutes and seconds.
#include <iostream>
#include <conio.h>
using namespace std;
class Timer
{
private:
int minutes;
int seconds;
public:
Time(){
minutes = 0;
seconds = 0;
}
Time(int m, int s){
minutes = m;
seconds = s;
}
void displayTime()
{
cout << "M: " << hours << " S:" << minutes <<endl;
}
Time operator++ ()
{
++seconds;
if(seconds >= 60)
{
++minutes;
seconds -= 60;
}
return Time(minutes, seconds);
}
Time operator++( int )
{
Time T(minutes, seconds);
++seconds;
if(seconds >= 60)
{
++minutes;
seconds -= 60;
}
return T;
}
};
int main()
{
Time T1(18, 23), T2(19,12);
++T1;
T1.displayTime();
++T1;
T1.displayTime();
T2++;
T2.displayTime();
T2++;
T2.displayTime();
_getch()
}
When I debug, it says
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp:13: error: ISO C++ forbids declaration of `Time' with no type
main.cpp:18: error: ISO C++ forbids declaration of `Time' with no type
main.cpp:29: error: ISO C++ forbids declaration of `Time' with no type
main.cpp:29: error: expected `;' before "operator"
main.cpp:40: error: expected `;' before "Time"
main.cpp:40: error: ISO C++ forbids declaration of `Time' with no type
main.cpp:40: error: expected `;' before "operator"
main.cpp:54: error: expected `;' before '}' token
main.cpp: In member function `void Timer::displayTime()':
main.cpp:26: error: `hours' undeclared (first use this function)
main.cpp:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp: At global scope:
main.cpp:56: error: new types may not be defined in a return type
main.cpp:56: error: extraneous `int' ignored
main.cpp:56: error: `main' must return `int'
main.cpp: In function `int main(...)':
main.cpp:57: error: `Time' undeclared (first use this function)
main.cpp:57: error: expected `;' before "T1"
main.cpp:59: error: `T1' undeclared (first use this function)
main.cpp:64: error: `T2' undeclared (first use this function)
main.cpp:69: error: expected `;' before '}' token
make.exe: *** [main.o] Error 1
Execution terminated
Object should be of type Timer not Time.
try to match class name and constructor name.
Hour member is not defined in displayTime method.
void displayTime()
{
cout << "M: " << minutes << " S:" << seconds <<endl;
}
Please refer following code
http://ideone.com/m50w2r

SOCKET does not name a type

As the question says, I am having an issue with the following code:
#pragma once
#include "includes.h"
#include "buffer.h"
class CSocket
{
bool udp;
int format;
char formatstr[30];
static sockaddr SenderAddr;
int receivetext(char*buf, int max);
public:
SOCKET sockid;
CSocket(SOCKET sock);
CSocket();
~CSocket();
bool tcpconnect(char*address, int port, int mode);
bool tcplisten(int port, int max, int mode);
CSocket* tcpaccept(int mode);
char* tcpip();
void setnagle(bool enabled);
bool tcpconnected();
int setsync(int mode);
bool udpconnect(int port, int mode);
int sendmessage(char*ip, int port, CBuffer* source);
int receivemessage(int len, CBuffer*destination);
int peekmessage(int size, CBuffer*destination);
int lasterror();
static char* GetIp(char*address);
static int SockExit(void);
static int SockStart(void);
static char* lastinIP(void);
static unsigned short lastinPort(void);
static char* myhost();
int SetFormat(int mode, char* sep);
};
I am using Code::Blocks. I'm getting the following error at build time:
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|15|error: ‘SOCKET’ does not name a type|
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|16|error: expected ‘)’ before ‘sock’|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|16|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|25|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|34|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|43|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|50|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|59|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|66|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|74|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|85|error: expected constructor, destructor, or type conversion before ‘(’ token|
||=== Build finished: 11 errors, 0 warnings ===|
I have included the following in the referenced includes.h:
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
Am i missing a directive or library? Is SOCKET spelled different? Any illumination would be great!
The socket file descriptor is just an integer. So replace SOCKET by int in your code, or use a typedef. (I'm not sure where you saw SOCKET before, but it's not standard.)