error: expected Primary-Expression before = - Error during object creation:

Asked

Viewed 382 times

0

  • NOTE: My teacher is teaching modularization in c++, so the files are all divided.

I am trying to implement point2d class, but when I try to compile the file by linux terminal, these errors occur:

rafaelchaves:~/workspace/Lista2-TecProg/q7 (master) $ make comp
g++ q7.cpp q7classfunc.cpp -o q7 -std=c++11 && ./q7
q7.cpp:5:13: error: expected primary-expression before ‘inicio’
point2d inicio;
        ^
q7.cpp:5:13: error: expected ‘}’ before ‘inicio’
q7.cpp:5:13: error: expected ‘,’ or ‘;’ before ‘inicio’
q7.cpp:8:1: error: expected declaration before ‘}’ token
}
^
make: *** [comp] Error 1

Below the link to the repository with the codes on github.

https://github.com/RafaelChavesPB/Lista-2--TecProg/tree/master/q7

q7classfunc.h file:

#include <iostream>
#include <iomanip>

using namespace std;

class point2d 
{
    protected:
        float m_x;
        float m_y;
    public:
        point2d(void);
        point2d(float newX,float newY);
        void print(void);
};

q7classfunc.cpp file:

#include "q7classfunc.h"


point2d::point2d(void){
    m_x=0;
    m_y=0;
}

point2d::point2d(float newX,float newY){
    m_x=newX;
    m_y=newY;
}

void point2d::print(){
    cout<<setprecision(2)<<fixed<<"Point2d("<<m_x<<","<<m_y<<");"<<endl;
}

Q7.cpp file:

#include "q7classfunc.h"

int main
{
    point2d inicio;
    point2d final(1,1);

}

1 answer

0


The "main" statement is wrong, it must be

int main() // note o "()"
{
  ....
}
  • thank you! it’s amazing how a mistake so beast makes us waste so much time kkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.