0

MS visual studio 2015. "Run code analysis on Solution" works. But "Build solution" FAILS. This is my code. I made a class "account" and defined some methods. I created an object for this class in another cpp file. This works fine, but i am unable to call any function mentod of this class. I dont know why

//AccountBluePrint.h
#include<iostream>
#include<string>
typedef unsigned long int INT;
using namespace std;

class account {

    INT accountNumber;

public:
    // get functions
    char getAccountType();
    bool getAccountStatus();
    INT getAccountNumber() const {
        return accountNumber;
    }


    //methods
    void createNewAccount();

};
//AccountBluePrint.cpp
#include"AccountBluePrint.h"



bool account::getAccountStatus() {
    return accountStatus;
}

char account::getAccountType() {
    return accountType;
}



void account::createNewAccount() {
    
    char checkAccountType;
}

//BankingAppSource.cpp()`
#include<iostream>
#include<fstream>
#include"AccountBluePrint.h"

void writeNewAccount();


int main() {

    char ch;
}



void writeNewAccount() {

    account accountObject;
    accountObject.createNewAccount();

}

Error is

1>------ Rebuild All started: Project: BankingApplication, Configuration: Debug Win32 ------
1>  BankingAppSource.cpp
1>  AccountBluePrint.h
1>  AccountBluePrint.cpp
1>  Generating Code...
1>Debug\AccountBluePrint.obj : warning LNK4042: object specified more than once; extras ignored
1>BankingAppSource.obj : error LNK2019: unresolved external symbol "public: bool __thiscall account::createNewAccount(void)" (?createNewAccount@account@@QAE_NXZ) referenced in function "void __cdecl writeNewAccount(void)" (?writeNewAccount@@YAXXZ)
 fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
alpha
  • 43
  • 9
  • 2
    you forgot to compile account.cpp – user253751 Sep 08 '20 at 12:07
  • You need to compile all cpp files together. We would need to know how you build your code before we can help. – Yksisarvinen Sep 08 '20 at 12:09
  • I am using VS2015. I just build my solution – alpha Sep 08 '20 at 12:15
  • I think, I have compiled all files. – alpha Sep 08 '20 at 12:17
  • Suprisingly, If I click "Run code analysis on solution". Then, it build succesfully – alpha Sep 08 '20 at 12:25
  • Try a clean build. Look at the output to make sure account.obj is being created as part of the build. Make sure it has the expected time / date. if that fails make sure that account.cpp is part of your solution in Solution Explorer. – drescherjm Sep 08 '20 at 12:35
  • 1
    The analysis phase does not actually link your object files together. Prove that account.cpp is being compiled by adding a syntax error to it or a `#error` preprocessor directive. – Botje Sep 08 '20 at 12:35
  • I tried to build it again after cleaning. I can see account.obj. It is created. But I am still getting this error. – alpha Sep 08 '20 at 12:37
  • As I said in question itself. I am able to compile it using "Run code analysis on Solution". Something is wrong with PC, code, or VS – alpha Sep 08 '20 at 12:46
  • @ Botje: I added a complete error log. – alpha Sep 08 '20 at 12:58
  • Try creating a brand new project and add your source files and headers to the brand new project. – drescherjm Sep 08 '20 at 12:59
  • ***warning LNK4042: object specified more than once; extras ignored*** Seems to indicate you at least have an issue with your project. – drescherjm Sep 08 '20 at 13:00
  • If you have separate folders maybe you have more than 1 `AccountBluePrint.cpp` file. – drescherjm Sep 08 '20 at 13:02
  • @drescherjm: It works by creating a brand new project. I added same same source and header files. It should some fault of MS 2015. Thanks Everyone – alpha Sep 09 '20 at 07:08

0 Answers0