I have been cracking my head over this one. I've searched all over and all I seem to find are issues with the same error messages but involving either building complete iphone apps or dealing with header files, all sorts of stuff.
I was just writing a simple C++ program, I wanted all the classes in one file because i'm to lazy. Not sure if that is the issue. This is for a very simple college assignment, but I can't keep working because Xcode gives me this error that has nothing to do with the actual code (based on what I've read). I haven't messed with anything other than the actual .cpp file, I don't even know how I could've messed this up. I've done multiple assignments the same way and have never run into this issue before.
//
// Devin Shawn Tripp
// Student ID: 11199100
// CSCE 1040!
// Hw2
//
// Created by Devin Tripp on 2/26/18.
// Copyright © 2018 Devin Tripp. All rights reserved.
//
// 6 classes - main is not a class
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "Classes.cpp"
using namespace std;
int main(int argc, const char * argv[]) {
/* Declare Variables */
//Students stud;
int choice = 0;
/* Create Menu */
while (choice != 4) {
printf("What do you want to do: \n");
printf("1: Add new Course \n2: Add New Student \n3: Add Enrollment \n4: Quit \n");
cin >> choice;
switch (choice) {
case 1:
//do something
// inventory.additem();
break;
case 2:
//do something
//stud.addStudent();
break;
case 3:
//do something
// sales.addOrder();
break;
case 4:
//do something
exit(0);
break;
default:
break;
}
}
return 0;
}
The file below obviously holds all of the classes that will be used in the main.cpp.
//
// Classes.cpp
// Hw2
//
// Created by Devin Tripp on 2/28/18.
// Copyright © 2018 Devin Tripp. All rights reserved.
//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "Classes.hpp"
using namespace std;
#define CHUNKSIZE 2
class Courses {
public:
private:
};
class Student {
public:
void setId(int id) { stud_id = id;}
int getId() { return stud_id;}
void setName(string na) { name = na; }
string getName() { return name;}
private:
int stud_id;
string name;
};
class Students {
public:
Students() {stud_cnt = 0; stud_cap = CHUNKSIZE; studs = new Student[CHUNKSIZE];}
~Students() { delete [] studs;}
void addStudent();
private:
int stud_cnt;
int stud_cap;
Student *studs;
};
void Students::addStudent() {
int id;
string temp;
if (stud_cnt == stud_cap) {
Student *temp;
temp = new Student[stud_cap + CHUNKSIZE];
for (int i = 0;i < stud_cnt; i++) {
temp[i] = studs[i];
}
delete [] studs;
stud_cap += CHUNKSIZE;
studs = temp;
}
printf("Enter a new student ID: ");
cin >> id; cin.ignore();
printf("Enter Name: ");
cin >> temp; cin.ignore();
cout << " Got data " << temp << endl;
studs[stud_cnt].setId(id); cout << "Set ID" << endl;
studs[stud_cnt].setName(temp); cout << "Set Name" << endl;
stud_cnt += 1; cout << "inc stud count" << endl;
}
I didn't use the header file although I think prob should that might be the issue because I don't declare the classes in there. Which I think that you are suppose to do.
here is the error message that I am receiving.
Ld /Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Products/Debug/Hw2 normal x86_64
cd "/Users/devintripp/Desktop/swift projects/Hw2"
export MACOSX_DEPLOYMENT_TARGET=10.13
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Products/Debug -F/Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Products/Debug -filelist /Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Intermediates.noindex/Hw2.build/Debug/Hw2.build/Objects-normal/x86_64/Hw2.LinkFileList -mmacosx-version-min=10.13 -Xlinker -object_path_lto -Xlinker /Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Intermediates.noindex/Hw2.build/Debug/Hw2.build/Objects-normal/x86_64/Hw2_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Intermediates.noindex/Hw2.build/Debug/Hw2.build/Objects-normal/x86_64/Hw2_dependency_info.dat -o /Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Products/Debug/Hw2
duplicate symbol __ZN8Students10addStudentEv in:
/Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Intermediates.noindex/Hw2.build/Debug/Hw2.build/Objects-normal/x86_64/Classes.o
/Users/devintripp/Library/Developer/Xcode/DerivedData/Hw2-dpzrwrfmzkaytqajxohtoaipzmkh/Build/Intermediates.noindex/Hw2.build/Debug/Hw2.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64