?
Solved

MS VC++6.0 -> link error.

Posted on 2005-03-30
6
Medium Priority
?
234 Views
Last Modified: 2010-04-24

Rebuild All , i got

Deleting intermediate files and output files for project 'sales - Win32 Debug'.
--------------------Configuration: sales - Win32 Debug--------------------
Compiling...
main.cpp
d:\vc++\sales\main.cpp(16) : error C2440: 'initializing' : cannot convert from 'class FullTimeSalesperson (__cdecl *)(void)' to 'class Salesperson *'
        There is no context in which this conversion is possible
Salesperson.cpp
FullTimeSalesperson.cpp
Error executing cl.exe.

sales.exe - 1 error(s), 0 warning(s)



=====================================================

#include <iostream>
#include <list>
#include "Salesperson.h"
#include "FullTimeSalesperson.h"
using namespace std;

int main(int argc, char* argv[])
{
//       list<Salesperson> myLinkListOfInt;
     cout << "hello Joyce" << endl;    
     cout << "hello Wilson." << endl;    

       FullTimeSalesperson salesF();
      
       Salesperson *salesPtr = &salesF;


//       cout << salesPtr->earnings();

       return 0;
}

======================================================


#ifndef SALESPERSON_H
#define SALESPERSON_H

#include <string.h>

class Salesperson {
      
public :
      Salesperson();

      char * getName ();
      double getCommissionRate ();

      double getQuantity ();
      virtual double earnings() const = 0;

private :
      char * name;      // name of the salesperson.
      double commissionRate; // amount get per item sold.
      double quantity; // total items sold for the month.
};

#endif

======================================================

#include "Salesperson.h"


Salesperson::Salesperson() {}



======================================================


#ifndef FULLTIMESALESPERSON_H
#define FULLTIMESALESPERSON_H

#include "Salesperson.h"

class FullTimeSalesperson : public Salesperson {
      
public :
      FullTimeSalesperson();

      virtual double earnings() const;

private :
      double hourlySalary;      // hourly Salary
      double hours;                   // hours done this month.
};

#endif


======================================================



#include "FullTimeSalesperson.h"
#include "Salesperson.h"

FullTimeSalesperson::FullTimeSalesperson() : Salesperson() {}


double FullTimeSalesperson::earnings() const { return 1;}

0
Comment
Question by:StanleyLMW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13662091
You need a casting, like:
Salesperson *salesPtr = (Salesperson *)&salesF;
0
 

Author Comment

by:StanleyLMW
ID: 13662335
Deleting intermediate files and output files for project 'sales - Win32 Debug'.
--------------------Configuration: sales - Win32 Debug--------------------
Compiling...
main.cpp
Salesperson.cpp
FullTimeSalesperson.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "class FullTimeSalesperson __cdecl salesF(void)" (?salesF@@YA?AVFullTimeSalesperson@@XZ)
Debug/sales.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

sales.exe - 2 error(s), 0 warning(s)
0
 

Author Comment

by:StanleyLMW
ID: 13662345
#include <iostream>
#include <list>
#include "Salesperson.h"
#include "FullTimeSalesperson.h"

using namespace std;

int main(int argc, char* argv[])
{
//       list<Salesperson> myLinkListOfInt;
     cout << "hello Joyce" << endl;    
     cout << "hello Wilson." << endl;    

       FullTimeSalesperson salesF();
      
       Salesperson *salesPtr = (Salesperson *) &salesF;


//       cout << salesPtr->earnings();

       return 0;
}
0
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 total points
ID: 13662381
use:

int main(int argc, char* argv[])
{
//      list<Salesperson> myLinkListOfInt;
     cout << "hello Joyce" << endl;    
     cout << "hello Wilson." << endl;    

      FullTimeSalesperson salesF;    //  <--- don't use parenthesis
     
      Salesperson *salesPtr = (Salesperson *) &salesF;


//      cout << salesPtr->earnings();

      return 0;
}
0
 

Author Comment

by:StanleyLMW
ID: 13662560

do not necessary do the casting. No casting is still work.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13662598
The real problem is the parenthesis, with parenthesis you are forcing to call a default constructor you have not implemented.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question