none
"Object 'ClassName' already exists" when creating a class!

    Question

  • Hello.

    I created a class called GTime but I removed it from the project folder. I also cleaned and rebuilt the project.

    Now I want to add it again but everytime I try... it says:

    I checked, but there's no trace of my GTime files!

    Saturday, September 3, 2016 12:21 PM

Answers

  • Hi gedamial,

    I am glad to know you have solved this issue, but I think this is normal phenomenon.

    When we add a class to the c++ project, and remove this class from project. Then if you want to add a same class again. I think we should not to crated a new same class to our project, because this class also exits in the folder of our project. At the moment you could through add-> Existing Item to add the removed class.

    In addition, you could choose delete the class in your project. Then the class will also be delete from the folder of project. Then you could add a new same class to this project.

    To delete the class please refer to the following step:

    Click the GTime class-> press delete on the keyboard-> then the following screenshot will be displayed->choose remove or delete option:

    If you choose remove, the class will not be delete from the folder of the project, it only be removed from the solution explorer. You could chose add an existing item to reload this class.

    If you choose delete, the class will be delete from solution explorer and the folder of project. You should create a new class to add it back to this project.

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, September 5, 2016 5:31 AM
    Moderator

All replies

  • Any tip?
    Sunday, September 4, 2016 10:02 AM
  • Hi,

    Check the folder of your project if it still has the class file you created initially, because the deletion you did may removed the file from the project but still exists in the folder you are hosting your files on.

    if you find it delete then try add the class again from the visual studio.


    Thanks, Mahmoud

    Sunday, September 4, 2016 11:18 AM
  • Make sure that there is no GTime in other existing files. Then create the new class GTime2, specifying the files GTime.h and GTime.cpp. Then change GTime2 to GTime manually or using Rename command (<F2>).

    Sunday, September 4, 2016 11:21 AM
  • I completely cleaned my folder. There's no trace of the word GTime anywhere!
    Sunday, September 4, 2016 11:21 AM
  • Make sure that there is no GTime in other existing files. Then create the new class GTime2, specifying the files GTime.h and GTime.cpp. Then change GTime2 to GTime manually or using Rename command (<F2>).

    Hi, that worked!

    Although it worked, I would like to know why Visual Studio was acting like a stupid.

    Thanks

    Sunday, September 4, 2016 2:18 PM
  • Hi gedamial,

    I am glad to know you have solved this issue, but I think this is normal phenomenon.

    When we add a class to the c++ project, and remove this class from project. Then if you want to add a same class again. I think we should not to crated a new same class to our project, because this class also exits in the folder of our project. At the moment you could through add-> Existing Item to add the removed class.

    In addition, you could choose delete the class in your project. Then the class will also be delete from the folder of project. Then you could add a new same class to this project.

    To delete the class please refer to the following step:

    Click the GTime class-> press delete on the keyboard-> then the following screenshot will be displayed->choose remove or delete option:

    If you choose remove, the class will not be delete from the folder of the project, it only be removed from the solution explorer. You could chose add an existing item to reload this class.

    If you choose delete, the class will be delete from solution explorer and the folder of project. You should create a new class to add it back to this project.

    Sincerely,

    Oscar


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, September 5, 2016 5:31 AM
    Moderator