locked
error C3861 with function call? RRS feed

  • Question

  • I am trying to write a program using windows form application. The windows form application takes four numbers input from textboxes, the numbers are then  converted to double type. This is done in Form1.h under the button click event handler. I created a seperate cpp called Wexlar.cpp with a function prototype that adds the four numbers and returns the sum.  Under Form1.h and the button event handler I call the function result and then change the double to a string to be displayed in a textbox. I keep getting error C3861 "identifier not found" asscociated with the function call. I have added what I think are the appropriate include statements but am still having problems. Any help would be appreciated . Thank you!

    The code is as follows:

    Form1.h

    #pragma once

    #include<iostream>


    .........

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    //Convert string input to double number

    double A = Convert::ToDouble(this->textBox1->Text);

    double B = Convert::ToDouble(this->textBox2->Text);

    double C = Convert::ToDouble(this->textBox3->Text);

    double D = Convert::ToDouble(this->textBox4->Text);

    double Sum; //Define variable type

    Sum = Wexlar(A, B, C, D); //Calls Wexlar function

    this->textBox5->Text = Sum.ToString(); //Converts result to string and displays

    }


    Wexlar.cpp

    include <stdafx.h>

    #include<iostream>

    #include "Form1.h"

    double Wexlar(double A, double B, double C, double D)

    {

    return A+B+C+D;

    }

    Wednesday, October 22, 2008 3:29 PM

Answers

  • Your code in Wexlar.cpp is a function definition, not a prototype. You need to put the prototype in Form1.h

    double Wexlar(double A, double B, double C, double D);

    Remember the C/C++ compilation model: each implementation (.cpp) file is compiled separately. Your Windows form application has (at least) two .cpp files:

    ProjectName.cpp (#includes Form1.h)
    Wexlar.cpp

    In your code, ProjectName.cpp does not know anything about the Wexlar() function.

    By the way, your Wexlar.cpp does not need to #include Form1.h (or iostream).






    David Wilkinson | Visual C++ MVP
    • Proposed as answer by ildjarn Wednesday, October 22, 2008 4:13 PM
    • Marked as answer by hydro1234 Wednesday, October 22, 2008 4:40 PM
    Wednesday, October 22, 2008 3:50 PM
  • Thank you!!!!! That work great

    G
    • Marked as answer by hydro1234 Wednesday, October 22, 2008 4:40 PM
    Wednesday, October 22, 2008 4:00 PM

All replies

  • Your code in Wexlar.cpp is a function definition, not a prototype. You need to put the prototype in Form1.h

    double Wexlar(double A, double B, double C, double D);

    Remember the C/C++ compilation model: each implementation (.cpp) file is compiled separately. Your Windows form application has (at least) two .cpp files:

    ProjectName.cpp (#includes Form1.h)
    Wexlar.cpp

    In your code, ProjectName.cpp does not know anything about the Wexlar() function.

    By the way, your Wexlar.cpp does not need to #include Form1.h (or iostream).






    David Wilkinson | Visual C++ MVP
    • Proposed as answer by ildjarn Wednesday, October 22, 2008 4:13 PM
    • Marked as answer by hydro1234 Wednesday, October 22, 2008 4:40 PM
    Wednesday, October 22, 2008 3:50 PM
  • Thank you!!!!! That work great

    G
    • Marked as answer by hydro1234 Wednesday, October 22, 2008 4:40 PM
    Wednesday, October 22, 2008 4:00 PM