• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

MS VC++6.0 -> link error.


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
StanleyLMW
Asked:
StanleyLMW
  • 3
  • 3
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
You need a casting, like:
Salesperson *salesPtr = (Salesperson *)&salesF;
0
 
StanleyLMWAuthor Commented:
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
 
StanleyLMWAuthor Commented:
#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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
Jaime OlivaresSoftware ArchitectCommented:
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
 
StanleyLMWAuthor Commented:

do not necessary do the casting. No casting is still work.
0
 
Jaime OlivaresSoftware ArchitectCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now