Compile Errors, Please Help

This is a discussion on Compile Errors, Please Help within the C++ Programming forums, part of the General Programming Boards category; Code: I using msvs2010 on vistaOS (so i am told i need to use include<stdafx.h> even though it doesnt appear ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Unhappy Compile Errors, Please Help

    Code:
    I using msvs2010 on vistaOS (so i am told i need to use include<stdafx.h> even though it doesnt appear in my stdlib?)
    so this is the code teaching me how to use class, in this case Fraction class:
    
    #include <stdafx.h>
    #include <stdlib.h>
    
    
    class Fraction {
    private:
    	int num, den;
    public:
    	void set(int n, int d) {num = n; den = d; normalize();}
    	int get_num() {return num;}
    	int get_den() {return den;}
    private:
    	void normalize();
    	int gcf(int a, int b);
    	int lcm(int a, int b);
    };
    
    void Fraction::normalize() {
    	if (den == 0 || num == 0) {
    		num = 0;
    		den = 1;
    	}
    	if (den < 0) {
    		num *= -1;
    		den *= -1;
    	}
    	int n = gcf(num, den);
    	num /= n;
    	den /= n;
    }
    
    int Fraction::gcf(int a, int b) {
    	if (a % b == 0)
    		return abs(b);
    	else
    		return gcf(b, a % b);
    }
    
    int Fraction::lcm(int a, int b) {
    	return (a / gcf(a, b)) * b;
    }
    
    
    OK, now here the output results:
    
    1>------ Build started: Project: Fract1, Configuration: Debug Win32 ------
    1>Build started 3/10/2011 9:50:21 PM.
    1>InitializeBuildStatus:
    1>  Touching "Debug\Fract1.unsuccessfulbuild".
    1>ClCompile:
    1>  All outputs are up-to-date.
    1>  All outputs are up-to-date.
    1>ManifestResourceCompile:
    1>  All outputs are up-to-date.
    1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    1>C:\Users\Jimmy\Documents\Visual Studio 2010\Projects\Fract1\Debug\Fract1.exe : fatal error LNK1120: 1 unresolved externals
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:00.41
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    
    
    I'm pulling my hair out checking to make sure everything is right and it seems to be, why is it not working?  this code is straightoutta the book C++without fear, and the answer code provided with the book.  cant wait to hear your answers :)

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    I belive that stdafx should not be used like
    Code:
    # include <stdafx.h>
    but
    Code:
    # include "stdafx.h"

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    thanks for replying, iidnt thinkt hat was the problem since i am instructed to use <stdafx> specifically in the book, and all the projects up til now (11chptrs) ran fine with that<>. I tried the " " you suggested though and still got the same result output.
    it seems to be looking for a main function? cant get it to compile.

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Did you write the main function somewhere?

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    there is no main() specified in the example exercise yet, maybe because im in the beginning of the chapter. but im goign to move ahead and try the next one i get teh smae prob ill post again. thanks again guys for trying...

    no i didnt write a main anywhere yet.

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Without main(), you will definitely get errors....
    Do
    Code:
    void main(){
    Fraction f;
    }

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    that did it...you da man thanks guys!

  8. #8
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Don't mention.....
    And i am amazed you directly started reading classes?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    It would be better if you used int main.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Don't really matter..... Can use either...

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    You really need to go read the standards at some point.

    This "well it works for me" attitude will see you come seriously unstuck when you start using different compilers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Quote Originally Posted by Mr.777 View Post
    Don't really matter..... Can use either...
    No, you can't.
    int main is the only standard function. The end.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange compile errors
    By csonx_p in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2008, 11:41 AM
  2. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 05:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21