Help with a build error in Visual Studio

In summary, this is a very simple program about Class with Inventory.h, Inventory.cpp and source.cpp. I reduced it to very simple just displaying two message and it just won't build. It gave me error message I don't follow even after reading the error code online. I follow the example and syntax from the book. I am running out of idea what to do.
  • #36
yungman said:
It is not a big problem if Ctrl-Z can recover as the rest of the program including Windows file explorer. The worst is even if I exit VS, the damage is done on the past projects and the future ones. How can VS don't have an option to NOT taking changes beyond the current project, that if I delete a folder, the same folder disappears in ALL my old projects like I showed in post 29.
I really doubt any damage is done to the projects. It sounds like maybe you just accidentally changed some settings in VS? Usually when someone changes global settings, they intend the changes to persist. It's like if you change the color settings on your TV, it will affect every movie you watch. But you haven't damaged your DVDs. You just need to figure out how to reset those settings to what they were before.

Have you tried resetting the settings?

https://stackoverflow.com/questions/26863/how-do-i-really-reset-the-visual-studio-window-layout

Maybe you toggled "show all files"?

Screenshot_2020-10-09_00-11-51.png


https://stackoverflow.com/questions/52633866/project-files-hidden-in-visual-studio
 
Last edited:
  • Like
Likes yungman
Technology news on Phys.org
  • #37
Jarvis323 said:
I really doubt any damage is done to the projects. It sounds like maybe you just accidentally changed some settings in VS? Usually when someone changes global settings, they intend the changes to persist. It's like if you change the color settings on your TV, it will affect every movie you watch. But you haven't damaged your DVDs. You just need to figure out how to reset those settings to what they were before.

Have you tried resetting the settings?

https://stackoverflow.com/questions/26863/how-do-i-really-reset-the-visual-studio-window-layout

Maybe you toggled "show all files"?

View attachment 270681

https://stackoverflow.com/questions/52633866/project-files-hidden-in-visual-studio

You really did it! Thank you! Thanks a Billion!
I have to watch it again to take down notes. I opened a new project, They are there! I looked at another old file, it's there.

I can't thank you enough. You just save VS for me. You are the expert in VS!
 
  • #38
yungman said:
You really did it! Thank you! Thanks a Billion!
I have to watch it again to take down notes. I opened a new project, They are there! I looked at another old file, it's there.

I can't thank you enough. You just save VS for me. You are the expert in VS!
Yeah, actually I notice in your post #16, in one of the images you have the "show all files" button and some other button pressed (yellow highlighted buttons) and the others you don't. I guess that was the problem?

I am just good at googling I guess? It's a skill you pick up as a programmer. You will run into problems all the time, and you have to know how to figure out the solutions by looking things up.
 
  • Like
Likes yungman
  • #39
Jarvis323 said:
Yeah, actually I notice in your post #16, in one of the images you have the "show all files" button and some other button pressed (yellow highlighted buttons) and the others you don't. I guess that was the problem?

I am just good at googling I guess? It's a skill you pick up as a programmer. You will run into problems all the time, and you have to know how to figure out the solutions by looking things up.
Remember the nose?! I watched that 1 minute video so many times as it's blur, also the tittle just blocked the top manual. Had to watch it over and over and guess. This is the steps:
-Tools-->Import and Export setting-->Reset all setting-->No, just reset setting, overwriting my current setting-->General-->click Finish.

I swear I saw the page Import and Export setting-->Reset all setting before. It just didn't click in my head as I never relate this to import and export setting. When I saw that part, I started to know where to look for that and found it.

You really make my day. I cannot live with one mistake and change everything in all projects. I don't blame the mouse, $hit happens, it's how you recover from it that matters. Now this is 1/2 minutes job, I can live with it.

While you are here, can you look at the last few lines of post 27 in how to declare const int d_size = 31; for the structure?

Thanks you so much.

Alan
 
  • #41
yungman said:
My only question I cannot resolve is if you look at the Inventory.h file, I try to use const int d_size to declare the size of the char array. It just would not work, it just didn't like it when I put in private, public, in the source.cpp. I tried everything
Here's from Inventory.h:
C++:
class Inventory
{
private:
    int d_size = 31;
public:
        struct invItem
        {
            const int d_size = 31;
            char desc[31];
            int qty;
            double price;
        };
Does it make sense that you have a public member, InvItem, that can be accessed outside of the class, but with a member that is private (d_size)?

Also, I don't know why you have a class with a nested struct inside it.
Since you're learning about classes right now, it makes more sense to start with simple examples and get a better understanding of how to work with classes and OOP in general. No need to add complications like file I/O and so on.

Here's a simpler version of your inventory program.
Inventory.h
Notice that there is no more struct, and that the three private members have member access functions to get or set the private members. Also, I'm using the STL string class rather than a C-style char array. If I want to be able to store objects on disk, I might go back to a fixed-size char array, but I think it's more important to get a better understanding of how classes work at this point.
C++:
#include <iostream>
#include <string>
using namespace std;

class InventoryItem
{
private:
    string desc;
    int qty;
    double price;

public:        
    string get_Desc();
    void set_Desc(string);
    int get_Qty();
    void set_Qty(int);
    double get_Price();
    void set_Price(double);
    void displayRec();    
};

Implementation of class member functions, Inventory.cpp
C++:
#include <iostream>
#include "Inventory.h"

#include <iomanip>
using namespace std;

string InventoryItem::get_Desc()
{
    return desc;
}

void InventoryItem::set_Desc(string str)
{
    desc = str;
}

int InventoryItem::get_Qty()
{
    return qty;
}

void InventoryItem::set_Qty(int number)
{ 
    qty = number;
}

double InventoryItem::get_Price()
{
    return price;
}

void InventoryItem::set_Price(double pr)
{
    price = pr;
}

void InventoryItem::displayRec()
{
    cout << setw(25) << left << " Description: " << desc << endl;
    cout << setw(25) << left << " Quantity: " << qty << endl;
    cout << setw(25) << left << " Price: " << "$" << price << "\n\n";
}

The driver, main.cpp
Short and sweet.
C++:
#include "Inventory.h"

int main()
{
    InventoryItem Inv;

    Inv.set_Desc("doodad");
    Inv.set_Qty(5);
    Inv.set_Price(8.0);

    Inv.displayRec();    
}
Output:
Code:
 Description:            doodad
 Quantity:               5
 Price:                  $8
yungman said:
You actually stop and delete the Header Files in one project and look at your older projects to see whether the Header Files is gone?
In 22 years I have never needed to do this. I have deleted files from many projects, but have never seen any side effects in other projects.
Jarvis323 said:
Have you tried resetting the settings?
And as Jarvis showed, have you (Alan) tried looking at the VS documentation or googling for answers?
 
  • Like
Likes yungman
  • #42
Mark44 said:
Here's from Inventory.h:
C++:
class Inventory
{
private:
    int d_size = 31;
public:
        struct invItem
        {
            const int d_size = 31;
            char desc[31];
            int qty;
            double price;
        };
Does it make sense that you have a public member, InvItem, that can be accessed outside of the class, but with a member that is private (d_size)?

Also, I don't know why you have a class with a nested struct inside it.
Since you're learning about classes right now, it makes more sense to start with simple examples and get a better understanding of how to work with classes and OOP in general. No need to add complications like file I/O and so on.

Here's a simpler version of your inventory program.
Inventory.h
Notice that there is no more struct, and that the three private members have member access functions to get or set the private members. Also, I'm using the STL string class rather than a C-style char array. If I want to be able to store objects on disk, I might go back to a fixed-size char array, but I think it's more important to get a better understanding of how classes work at this point.
C++:
#include <iostream>
#include <string>
using namespace std;

class InventoryItem
{
private:
    string desc;
    int qty;
    double price;

public:     
    string get_Desc();
    void set_Desc(string);
    int get_Qty();
    void set_Qty(int);
    double get_Price();
    void set_Price(double);
    void displayRec(); 
};

Implementation of class member functions, Inventory.cpp
C++:
#include <iostream>
#include "Inventory.h"

#include <iomanip>
using namespace std;

string InventoryItem::get_Desc()
{
    return desc;
}

void InventoryItem::set_Desc(string str)
{
    desc = str;
}

int InventoryItem::get_Qty()
{
    return qty;
}

void InventoryItem::set_Qty(int number)
{
    qty = number;
}

double InventoryItem::get_Price()
{
    return price;
}

void InventoryItem::set_Price(double pr)
{
    price = pr;
}

void InventoryItem::displayRec()
{
    cout << setw(25) << left << " Description: " << desc << endl;
    cout << setw(25) << left << " Quantity: " << qty << endl;
    cout << setw(25) << left << " Price: " << "$" << price << "\n\n";
}

The driver, main.cpp
Short and sweet.
C++:
#include "Inventory.h"

int main()
{
    InventoryItem Inv;

    Inv.set_Desc("doodad");
    Inv.set_Qty(5);
    Inv.set_Price(8.0);

    Inv.displayRec(); 
}
Output:
Code:
 Description:            doodad
Quantity:               5
Price:                  $8
In 22 years I have never needed to do this. I have deleted files from many projects, but have never seen any side effects in other projects.
And as Jarvis showed, have you (Alan) tried looking at the VS documentation or googling for answers?
Thanks for you reply. I intentionally make it more complicate for the program just to make it more difficult. That's what I usually do. If I just follow the book, I would have a lot less questions as they are very easy. I know, the program is stupid, it was a program I wrote when I was in advanced file chapter, that was an improvised program already, this take it to the next level. My goal is to put a struct into the header file.

I find if I google, I have to know what key words I type in. If I put in wrong words, different things will come out and going nowhere. Believe me, I spent a lot of time googling this and the d_size issue. I tried not to ask question here until I spent a few hours searching. Even looking at VS document from MS, I have to know what to ask. You cannot just say I delete the header files, how can I get it back!

I would have never seen the issue of deleting the folder until very lately. Remember I was working on putting .h files using Add-->Existing and it doesn't work on mixed with Add-->New? When I start running into problem in building solution, I had to delete the .h file and put it somewhere. That's when I started to see the folder disappears. I experiment a lot, adding things, try it out, now working, delete them and try again. I find that's the best way to learn. You ever actually try deleting the folder and see your other project. If that doesn't happen to you, then I have to question whether I have problem in installing the VS again.

I forgot to delete the const int d_size = 31. It's not being used as I put [31] in.

Anyway, thanks so much to have the patience to help me. I feel very lazy today, have not even try doing any C++. This is the first day in at least the last 3 weeks that I have not done any C++ yet. that's why I have time to blow some hot air in the other thread. Usually I am too drown in C++ for any of that. I spent a lot of time, at least 4 to 8 hours a day, 7 days a week in the last 3 months on C++.

Alan
 
  • #43
yungman said:
Thanks for you reply. I intentionally make it more complicate for the program just to make it more difficult. That's what I usually do.
Yes, that's what you usually do, but in my experience, that's not a good way to learn things. Many times you have made things so difficult that you don't understand what you're doing. You're at the very beginning of learning about classes -- why make things harder on yourself? You have to crawl before you can walk, and you have to walk before you can run.
yungman said:
When I start running into problem in building solution, I had to delete the .h file and put it somewhere. That's when I started to see the folder disappears. I experiment a lot, adding things, try it out, now working, delete them and try again. I find that's the best way to learn. You ever actually try deleting the folder and see your other project. If that doesn't happen to you, then I have to question whether I have problem in installing the VS again.
I think your installation is probably just fine. Things would work a lot better if you stopped deleting this and that at random. I can't think of any good reason to delete a Solution Explorer "folder" like Header Files or Source Files. As I mentioned before, there are two options in VS for getting rid of your program files -- on the right-click menu for a program file (.cpp or .h) there are Remove and Exclude from Project. The Remove option actually deletes the file, and Exclude from Project leaves the file in place, but doesn't use it in the build. All of this information can be found the the Help for VS.
 
  • Like
Likes Jarvis323 and Vanadium 50
  • #44
yungman said:
When I start running into problem in building solution, I had to delete the .h file and put it somewhere. That's when I started to see the folder disappears. I experiment a lot, adding things, try it out, now working, delete them and try again. I find that's the best way to learn. You ever actually try deleting the folder and see your other project. If that doesn't happen to you, then I have to question whether I have problem in installing the VS again.

I don't think it was deleting things alone that caused your problem. I think you toggled the "show all files" button that I put a green box around. You can see in your post 16, you had it unpressed, then had it pressed (compare the two images). Try pressing it ON/OFF and see what happens.

Here it is unpressed.

unpressed.png


Here it is pressed.

pressed.png


Of course deleting things you're not supposed to, or in ways you're not supposed to might have messed things up as well, if that's what you did. But deleting something in one project alone would not have changed your other projects (unless it was a file that both projects are using).
 
Last edited:
  • #45
Mark44 said:
Yes, that's what you usually do, but in my experience, that's not a good way to learn things. Many times you have made things so difficult that you don't understand what you're doing. You're at the very beginning of learning about classes -- why make things harder on yourself? You have to crawl before you can walk, and you have to walk before you can run.
I think your installation is probably just fine. Things would work a lot better if you stopped deleting this and that at random. I can't think of any good reason to delete a Solution Explorer "folder" like Header Files or Source Files. As I mentioned before, there are two options in VS for getting rid of your program files -- on the right-click menu for a program file (.cpp or .h) there are Remove and Exclude from Project. The Remove option actually deletes the file, and Exclude from Project leaves the file in place, but doesn't use it in the build. All of this information can be found the the Help for VS.

Actually programming wise, it's very smooth. I spent so much time on VS, but after I resolved the file folder issue, it only took me like 15 minutes to make the program work exactly what I want the program to do. I was actually working in the car waiting for my big boss's doctor appointment, I bring up the program step by step and 15 minutes it worked. I had to take a double take to make sure.

The exercise in the book mostly very easy, I don't think I learn too much from the book if I don't venture out. Funny now that I got through all these, I looked at the next sample program, the book is doing the same Inventory like my program. I don't know whether it is as difficult as mine. I find going out of comfort zone and venture out is the best way to learn, Like I spent so much time on pointers and pointer to pointers. Now I feel very comfortable with it.

A lot of times, I look at the sample briefly in the book, then I just make up my own program and try to add what I learn from the pass chapters in. Like I added files, structures into this program and I add seekp() and seekg(). As I get older, memory is fading, I need to keep practice what I learn to make it part of me.

Speaking about learning, I just found out my Gaddis book is only the brief version. It stop after Inheritance and Polymorphism. I just bought the same book but not the brief version. It contains 4 more chapters on data structure on Exceptions, Function Templates, List, STL stack, queue and binary trees.
https://www.amazon.com/gp/product/0321545885/?tag=pfamazon01-20 I also bought bought this book by Gaddis on graphic and gaming:
https://www.amazon.com/gp/product/032151291X/?tag=pfamazon01-20
This one seems a lot easier, a lot of memory mapping of screen, drawing stuffs. Doesn't get to Class until later chapters..

I wonder which way to go first. I bet the data structure is going to be harder, the graphic is more fun and easier. What is your opinion on which one to first? I remember you advice to study minimum to Chapter 14 on Classes up to overload. I decided to finish at least the whole book to Inheritance and Polymorphism before I stop. It's only two chapters away, why stop. Just what is the next step.

Thanks
 
  • #46
Jarvis323 said:
I don't think it was deleting things alone that caused your problem. I think you toggled the "show all files" button that I put a green box around. You can see in your post 16, you had it unpressed, then had it pressed (compare the two images). Try pressing it ON/OFF and see what happens.

Here it is unpressed.

View attachment 270712

Here it is pressed.

View attachment 270713

Of course deleting things you're not supposed to, or in ways you're not supposed to might have messed things up as well, if that's what you did. But deleting something in one project alone would not have changed your other projects (unless it was a file that both projects are using).
I just went back and toggle that button. Now I see Header Files and Source Files either way. It was not like this before. I think I deleted the files. I cannot say for sure whether I press that before, but it started out deleting the .h file when I was experimenting with Add-->Existing vs Add-->New. That's when I deleted the .h and create new one back and fore.

BTW, I still need to try your last post#40. I am on strike today, just being bad. I have not tough any C++, just here yapping. I'll be back on this later or tomorrow.

Thanks for your help.
 
  • #47
yungman said:
I cannot say for sure whether I press that before
Yeah you can. There is conclusive proof that you did in post #16.
 
  • #49
In the process of playing with the last declaration, I notice something about the Header and Source Files. I can open and close the folders in the Solution Explorer. I don't know what view you call, please let me know. Here are the 4 pictures( I actually had to use a camera to take pictures as it won't show what view I was in if I click the screen capture apt.

This is the picture of both Header and Source Files closed as you can see the icon(folder closed). All the .h and .cpp files disappeared. Program ran but garbage in the record.
SE top Files closed.jpg


This is still with folder closed, just the .sln view as shown. Notice in the Header Files, there supposed to have Inventory.h in it. I NEVER put it there. This is the project that work from yesterday before I learn how to reset the VS. I have all 3 files in the Source File folder. You'll see later when I open the folders below.
SE bottom Files closed.jpg
This is the view with both folders opened. Notice all 3 files are in Source Files folder? This is what I put in.
SE top Files open.jpg


This is the view after I opened the folders. It looks pretty much the same as when the folders are closed. Notice in both close and open, the folders in this view looks open.
SE bottom Files open.jpg
This is something new to me. The program won't run right if the both Files folders are closed. What do you call this open and close folders. Does that means I have to look to make sure the folders is open?

Also, I don't know where the Inventory.h in the Header Files folder comes from. I did not put it there for sure. Last I worked on the program before resetting VS, I had all 3 in Source Files folder.

What do you call the two views, one is pointing to the top Inventory(C:...) and the bottom Inventory.sln. If I go on google to look, what should I type in? I am not having much luck doing searching. I don't know these terms, I don't think it helps if I type in " Header folder open and close in Solution Explorer"!

I never know to look at each folder icon.

Thanks
 
Last edited:
  • #50
yungman said:
This is something new to me. The program won't run right if the both Files folders are closed. What do you call this open and close folders. Does that means I have to look to make sure the folders is open?
"Collapsing" and "expanding" the folders is what you call this. These have nothing to do with whether the program runs or not. They are just views of the hierarchy that VS shows you. The program files are still there (unless you deleted them).
 
  • #51
Mark44 said:
"Collapsing" and "expanding" the folders is what you call this. These have nothing to do with whether the program runs or not. They are just views of the hierarchy that VS shows you. The program files are still there (unless you deleted them).

Funny it doesn't do that anymore.

What is the purpose of opening and closing the folders?

Thanks
 
  • #52
yungman said:
What is the purpose of opening and closing the folders?
(Sigh...)
What's the purpose of opening and closing a door?
 
  • Like
Likes Vanadium 50
  • #53
Mark44 said:
(Sigh...)
What's the purpose of opening and closing a door?
But if you close the door, you cannot access inside. You can access the folder whether it's open or not, that's the difference. If you close the folder, you cannot run the program, then it makes the whole world of sense. That's just common sense. Right?
 
  • #54
yungman said:
If you close the folder, you cannot run the program, then it makes the whole world of sense.
If you open the folder or the door, you can see inside. Having a folder open or closed in Solution Explorer makes exactly zero difference as to whether you can run the program.
yungman said:
That's just common sense. Right?
Nope.
 
  • #55
Mark44 said:
If you open the folder or the door, you can see inside. Having a folder open or closed in Solution Explorer makes exactly zero difference as to whether you can run the program.
Nope.
I guess we have a different definition of common sense. If the door is close, I cannot see inside, BUT I can just walk in and take anything I want and change anything I want? ....Anyway, this is off the subject, now I know. Maybe that's part of why I find it so difficult to read in CS stuff on line.

I actually took the time last night to read the VS site, it is very hard to read, same as going online and search.
 
  • #56
yungman said:
If the door is close, I cannot see inside, BUT I can just walk in and take anything I want and change anything I want?

No, but you can still press a button outside the room that makes a machine inside run.
 
  • #57
yungman said:
guess we have a different definition of common sense.
Apparently.
yungman said:
If the door is close, I cannot see inside, BUT I can just walk in and take anything I want and change anything I want?
If the door is closed, you can't see inside. If the door is open, you can see inside. It's the same idea with the open (expanded) or closed (collapsed) folders in Solution Explored. Again, whether the folders are collapsed or expanded, it makes no difference as far as whether the program will run. If your program won't run, it's because of something else entirely.
yungman said:
I actually took the time last night to read the VS site, it is very hard to read, same as going online and search.
This page in the docs -- https://docs.microsoft.com/en-us/visualstudio/get-started/visual-studio-ide?view=vs-2019 -- would be a good place to start. Other topics in this section are:
  • About the code editor
  • About projects and solutions (which would have answered a lot of the questions you've had)
  • More Visual Studio features
There are also tutorials that focus on the different languages that VS supports. If you want to learn how to use Visual Studio, going to the source is better than some random online search. That's common sense ...
 
  • Like
Likes yungman
  • #58
@yungman, please start a new thread with this question. Your post has nothing to do with build errors in VS.
 
  • Like
Likes Vanadium 50

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
22
Views
2K
Replies
10
Views
957
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
811
  • Programming and Computer Science
Replies
6
Views
916
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
30
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
Back
Top