Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to use simple function in Windows Form application

Posted on 2010-11-11
7
Medium Priority
?
739 Views
Last Modified: 2012-05-10
Hello experts.

Created simple windows form application in VC++ 2008.

Please have a look at the code below:

private: System::Void listBox1_Click(System::Object^  sender, System::EventArgs^  e)
                   {
                         String^ s;

                         if ( listBox1->SelectedIndex != -1 )
                              s = listBox1->SelectedItems[0]->ToString();

                         aaa(1);
   
                         
                         

                   }
      };


As you can see, I try to call "aaa(1)".


My "Headers.h":

#include "stdafx.h"

int aaa(int a);



My "Functions.cpp":

#include "stdafx.h"

int aaa(int a)
{
      return -1;
      
}




But get two errors:

OpenCV tester.obj : error LNK2028: unresolved token (0A00000A) "int __clrcall OpenCVtester::aaa(int)" (?aaa@OpenCVtester@@$$FYMHH@Z) referenced in function "private: void __clrcall OpenCVtester::Form1::listBox1_Click(class System::Object ^,class System::EventArgs ^)" (?listBox1_Click@Form1@OpenCVtester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
OpenCV tester.obj : error LNK2019: unresolved external symbol "int __clrcall OpenCVtester::aaa(int)" (?aaa@OpenCVtester@@$$FYMHH@Z) referenced in function "private: void __clrcall OpenCVtester::Form1::listBox1_Click(class System::Object ^,class System::EventArgs ^)" (?listBox1_Click@Form1@OpenCVtester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

Why is that?



Thank you

panJames
0
Comment
Question by:panJames
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:panJames
ID: 34112497
And of course I added:

#include "Headers.h"


panJames
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 34113654
Did you try:
::aaa(1);  // calling function with global scope
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 34113663
What are you trying to do?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:panJames
ID: 34119257
I am just learning/ experimenting.

Did what u suggested. Got an error:

error C2039: 'aaa' : is not a member of '`global namespace''

panJames
0
 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 34119269
I think your aaa() is written inside a class???

If so, then Use
int ClassName::aaa(int a) {
  // Write your code ...
  return -1;
}
0
 

Author Comment

by:panJames
ID: 34119429
Subrat, as mentioned in my first post:

My "Functions.cpp":

#include "stdafx.h"

int aaa(int a)
{
      return -1;
     
}

panJames
0
 
LVL 9

Accepted Solution

by:
Subrat (C++ windows/Linux) earned 2000 total points
ID: 34133362
Include headers.h in Functions.cpp and wherever you are using aaa() there, include "Headers.h"
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

916 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