Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I can't get this project to run and all the files run as is in MSVS - C++

+1 vote
asked May 5, 2020 by Eric VanSchaick (240 points)
I would appreciate it if this is a simple fix lmk what I am doing wrong.  I've modified this program already from the textbook to work in MSVS. This project works as is in MSVS. I tried compiling in C++, C++ 14, C++ 17.

here is the project:

https://onlinegdb.com/Syn9Qby5U

1 Answer

0 votes
answered Jun 12, 2020 by Peter Minarik (101,360 points)
edited Jun 18, 2020 by Peter Minarik

You should include pegclass.h and iostream in pegclass.cpp

#include "pegclass.h"
#include <iostream>
using namespace std;

In pegclass.h you really shouldn't include any source file, so remove

#include "pegclass.cpp" // <-- REMOVE THIS!!!

from pegclass.h. Including source in header files is a really bad practice.

Same for vector.h: do not include vector.cpp from its header.

#include "vector.cpp" // <-- REMOVE THIS!!!

After all these changes, the code compiles.

But it still does not link.

After some looking at the code, I remembered that if you do generics (template), you cannot separate your generic class into a header (.h) and code file (.cpp). This is a thing with generics and has to do with how the actual code with the actual type is generated from the templates.

So what you need to do is keep the generic class (vector) in one file. In practice it means that you just have a vector.h that contains not only the declaration but the definition as well, no separate vector.cpp

I've changed your code and now it compiles and runs: https://onlinegdb.com/SJzFUHup8

Note: I didn't go beyond compilation and running, I did not validate if your program works correctly.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...