I would like to know why I am having problems with non-existent files even though they are in the same directory.
This is my file organization:
I get the error:
I've already changed the folder files, and it still doesn't work, I'd like to understand what's happening and how I could solve it.
I'm using VScode, after researching more about the compiler, in tasks.json I changed it using an argument like "${workspaceFolder}/*.cpp" instead of "${file}", just as I discovered in an IDE tutorial , the code works if I put all the member functions in the .h files, but I still want to understand why, and how I can configure my compiler, apparently, even with the modifications I make to the settings it doesn't work. Could it have something to do with my compiler version?
Main.cpp:
#include "Vector3d.h"#include "Point3d.h"int main(){ Point3d p { 1.0, 2.0, 3.0 }; Vector3d v { 2.0, 2.0, -3.0 }; p.print(); p.moveByVector(v); p.print(); return 0;}
Vector3d.h:
// Header file that defines the Vector3d class#ifndef VECTOR3D_H#define VECTOR3D_H#include "Point3d.h" // for declaring Point3d::moveByVector() as a friendclass Vector3d{ private: double m_x{}; double m_y{}; double m_z{}; public: Vector3d(double x, double y, double z); void print() const; friend void Point3d::moveByVector(const Vector3d& v);};#endif
Vector3d.cpp:
// Member functions of the Vector3d class defined here#include "Vector3d.h" // Vector3d class defined in this file#include <iostream>Vector3d::Vector3d(double x, double y, double z) : m_x{x}, m_y{y}, m_z{z}{}void Vector3d::print() const{ std::cout << "Vector(" << m_x << " , " << m_y << " , " << m_z << ")\n";}
Point3d.h:
// Header file that defines the Point3d class#ifndef POINT3D_H#define POINT3D_Hclass Vector3d; // forward declaration for class Vector3d for function moveByVector()class Point3d{ private: double m_x{}; double m_y{}; double m_z{}; public: Point3d(double x, double y, double z); void print() const; void moveByVector(const Vector3d& v); // forward declaration above needed for this line};#endif
Point3d.cpp:
// Member functions of the Point3d class defined here#include "Point3d.h" // Point3d class defined here#include "Vector3d.h" // for the parameter of the function moveByVector()#include <iostream>Point3d::Point3d(double x, double y, double z) : m_x{x}, m_y{y}, m_z{z}{}void Point3d::moveByVector(const Vector3d& v){ // Add the vector components to the corresponding point coordinates m_x += v.m_x; m_y += v.m_y; m_z += v.m_z;}void Point3d::print() const{ std::cout << "Point(" << m_x << ", " << m_y << ", " << m_z << ")\n";}
my task.json:
{"version": "2.0.0","tasks": [ {"label": "build all C++ files","type": "shell","command": "C:/MinGW/bin/g++", "args": ["-g", "Ex1_T15.9PorArquivos/*.cpp", "-o", "build/my_program" ],"group": {"kind": "build","isDefault": true },"problemMatcher": ["$gcc"],"detail": "Compiles all C++ files in src/" } ]}