i have to write main function to test my project \" SIMPLES_GRADES\" and i use X
ID: 3672503 • Letter: I
Question
i have to write main function to test my project " SIMPLES_GRADES" and i use Xcode 6.2
here is my main.cc
#include <iostream>
#include "p0.h"
using namespace std;
int main()
{
SIMPLEST_GRADES g;
g.SIMPLEST_READ();
g.SIMPLEST_AVE(2);
return 0;
}
here is my header file
#ifndef p0_p0_h
#define p0_p0_h
#include <stdio.h>
class SIMPLEST_GRADES
{
public:
SIMPLEST_GRADES(void);
void SIMPLEST_READ(void);
void SIMPLEST_AVE(int);
private:
int n;
int id[20];
int e1_grades[20];
int e2_grades[20];
int e3_grades[20];
float average;
};
#endif
Here is the error massage:
Undefined symbols for architecture x86_64:
"SIMPLEST_GRADES::SIMPLEST_AVE(int)", referenced from:
_main in main.o
"SIMPLEST_GRADES::SIMPLEST_READ()", referenced from:
_main in main.o
"SIMPLEST_GRADES::SIMPLEST_GRADES()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Explanation / Answer
Yes, we will get warnings like .. undefined reference to SIMPLEST_AVE(int) etc..
because .. we are using header file here .. but in this header file we are trying to build class methods ..
But c++ wont accept ... we must define in in another .cpp format to overload the methods.
Second one: we declared function prototypes, but function implementations are missing.
Third one: This include statement fails "#ifndef p0_p0_h"
Fourth one: When writing methods .. we must "::" operator.
ex: void SIMPLEST_GRADES::SIMPLEST_AVE(int num) { }
You not declared in this format, so it was giving error .. undefined reference error ..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.