Thread: Need help get this working

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    Thanks linucksrox !

    Here's the .cpp file that I have done.

    Code:
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    
    using std::string;
    using namespace std;
    
    #include "personType.h"
    
    personType::personType()   	 //Default constructor;
    	{
      	    firstName; //store the first name    
    		lastName;  //store the last name
    	}
    void personType::print() const 
    		 {
    	cout <<"\nThe name is: "<<firstName<<" "<<lastName<<endl;;
    		 }
    void personType::setName(string first, string last)
    {
    		firstName = first;
    		lastName = last;
    }
    It seems that it's coming from the print function.
    Last edited by flicka; 10-23-2005 at 03:18 PM.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    I have reworked my program completely and I am now getting linking error when I use the compiler.
    Here is my header file:
    Code:
    #ifndef H_personType
    #define H_personType
    
    #include <string>
    
    using namespace std;
    
    class personType
    {
    public:
        void print() const;
        
        void setName(string first, string last);
        
        string getFirstName() const;
        
        string getLastName() const;
          
        personType(string first = "", string last = "");
           
     private:
        string firstName; //variable to store the first name
        string lastName;  //variable to store the last name
    };
    
    #endif
    Here my .cpp file:
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    #include "personType.h"
    
    
    void personType::print() const
    {
    	cout << firstName << " " << lastName;
    }
    
    void personType::setName(string first, string last)
    {
    	firstName = first;
    	lastName = last;
    }
    
    string personType::getFirstName() const
    {
    	return firstName;
    }
    
    string personType::getLastName() const
    {
    	return lastName;
    }
    
    	//constructor
    personType::personType(string first, string last) 
    
    { 
    	firstName = first;
    	lastName = last;
    }
    Here are the error messages I get:

    Code:
    ------ Build started: Project: ATest1, Configuration: Debug Win32 ------
    Compiling...
    ATest1.cpp
    Linking...
    MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
    Debug\ATest1.exe : fatal error LNK1120: 1 unresolved externals
    ATest1 - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Can anyone explain to me what this means and how I can fix this please.
    Thanks so much
    Last edited by flicka; 10-23-2005 at 06:06 PM.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Not excatly sure but i dont see any main() anywhere there? is there a third file to this im assuming?
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    45
    Well No third file for this one.

    I'm want first to get this one to print the first and last name and then I'll try to do one with or an adress book or a payroll type thing. It's more to understand the way to do it right because I see all these projects with headers and .cpp files.

    So should I add an int main ()??

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    C++ Help!

    Hello every one, This is my 1st post. I have the same assignment as the Thread starter, I figured I would post my question here.
    I'm using VB 2010 express to compile and I choose the C++ version.


    I know Im missing some things including code in my .cpp definitions of functions, but that's half of where Im confused and I had to run out to take a test, maybe when I get back in 4 hours someone will have some things to add. Thanks in advance. I Could also be reached @ Twitter

    Here is my CODE:l

    Code:
    #ifndef PersonType_H
    #define PersonType_H
    
    
    
    
    class PersonType
    {
    public:
    	PersonType();//Defualt Constructor
        PersonType(string, string);//Constructor with parameters
        
        void setName(string first, string last);//Function to set firstName and lastName
    	void getName(string& first, string last);//Function to return firstName and lastName through the parameters	    
    	void print() const;    //Function to output the first name and last name
    private:
       string firstName; //DataMember first name    
       string lastName;  //DataMember last name
    
    
    };
    #endif
    
    #include "stdafx.h"
    #include <iostream>
    #include <cstring>
    
    
    using std::cout;
    using std::endl;
    using namespace std;
    
    #include "PersonType.h"
    
    PersonType::PersonType(string first, string last)//Default constructor;
    	{
      	    firstName = fist; //store the first name    
    		lastName = last;  //store the last name
    	}
    
    void personType::setName(string first, string last)
    	{
    		firstName = first;
    		lastName = last;
    	}
    void PersonType::getName()
    	{
    
    	}
    
    void PersonType::print()const 
        {
    		cout<<firstName<<" "<<lastName;
    	}
    
    #include "stdafx.h"
    using namespace System;
    #include <cstdlib>
    #include <iostream>
    
    
    #include "PersonType.h"
    
    int main()
    {
       PersonType pName(David, Barco);
       const pName.setName;
       const pName.getName;
       const pName.printName;
       
       
       
        system("PAUSE");
        return EXIT_SUCCESS;
    }


    ERRORS:

    C++ WA 4 B2.cpp(8): warning C4603: 'PersonType_H' : macro is not defined or definition is different after precompiled header use
    Add macro to precompiled header instead of defining here
    C++ WA 4 B2.cpp(30) : use of precompiled header
    C++ WA 4 B2.cpp(39): fatal error C1083: Cannot open include file: 'PersonType.h': No such file or directory

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM