Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
compiling error
(1/1)
cpp_fanatic:
I'm writing a lesson code from a C++ for dummies book and ran into this error.
--- Code: ---/*
CallMemberFunction - define and invoke a function
that a member of the class Student
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class Student
{
public:
// add a completed course to the record
double addCourse(int hours, double grade)
{
// calculate the sum of all courses times
// the average grade
double weightedGPA;
weightedGPA = semesterHours * gpa;
// now add in the new course
semesterHours += hours;
weightedGPA += grade * hours;
gpa = weightedGPA / semesterHours;
// return the new gpa
return gpa;
}
int semesterHours;
double gpa;
};
int main(int nNumberofArgs, char* pszArgs[])
{
// create a Student object and initialize it
Student s;
s.semesterHours = 3;
s.gpa = 3.0;
// the values before the call
cout << "Before: s = (" << s.semesterHours
<< ", " << s.gpa << ")" << endl;
// the following subjects the data members of the s
// object to the member function addCourse()
cout << "Adding 3 hours with a grade of 4.0" << endl;
s.addCourse(3, 4.0); // call the member function
// the values are now changed
cout << "After: s = (" << s.semesterHours
<< ", " << s.gpa << ")" << endl;
// wait until user is ready before terminating program
// to allow the user to see program results
cout << "Press Enter to continue...." << endl;
cin.ignore(10,'\n');
cin.get();
return 0;
}
--- End code ---
--- Code: ---||=== Build: Debug in CallMemberFunction (compiler: GNU GCC Compiler) ===|
||error: ld returned 1 exit status|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
--- End code ---
I started this on a windows 11 home laptop and then tried to compile it on a windows 11 pro computer and ran into this problem. I added these two compiler flags to the IDE -static-libgcc -static-libstdc++ and still getting this error, any help greatly appreciated.
MichaelAgarkov:
--- Code: ---error: ld returned 1 exit status
--- End code ---
is usually fixed by reinstalling the compiler. Here's others who got the same error.
Miguel Gimenez:
Post a full rebuild log, read this carefully for instructions.
EDIT: You are using the wrong forum, this is for C::B development only. Next time select another, for example Help.
Navigation
[0] Message Index
Go to full version