Solved

Trying to use simple function in Windows Form application

Posted on 2010-11-11
7
729 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 8

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 8

Accepted Solution

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

808 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