1 solution, 2 projects: how to use function form project B into project A

U

unknown;

hello,

i've got a question about using a function from project B in project A.
The projects are both in the same solution (using Microsolft Visual
Studio 2005)
the projects ara both native C++.

i've already added a reffrence from projectB into projectA.

i've got a function in projectA:
mainClass.cpp:
int main ()
{
int i = 0;
// i want to use function from project B like this:
// i = functionFromProjectB (10);
return i;
}


and in project B:
fileX.cpp:
int functionFromProjectB (int i)
{
return i * 4;
}



i know, the example is a little stange but it may be usefull to explain
my problem.

my question is how to do this or is this a .NET functionality and not
possible with native C++ projects.
 
D

David Wilkinson

unknown; said:
hello,

i've got a question about using a function from project B in project A.
The projects are both in the same solution (using Microsolft Visual
Studio 2005)
the projects ara both native C++.

i've already added a reffrence from projectB into projectA.

i've got a function in projectA:
mainClass.cpp:
int main ()
{
int i = 0;
// i want to use function from project B like this:
// i = functionFromProjectB (10);
return i;
}


and in project B:
fileX.cpp:
int functionFromProjectB (int i)
{
return i * 4;
}



i know, the example is a little stange but it may be usefull to explain
my problem.

my question is how to do this or is this a .NET functionality and not
possible with native C++ projects.

unknown;:

Are you related to IUnknown?

The easiest thing to do is just to add fileX.cpp to both projects. Of
course that means it will be compiled twice if you change it (unless you
make the output directories the same).

David Wilkinson
 
B

Bruno van Dooren [MVP VC++]

i've got a question about using a function from project B in project A.
The projects are both in the same solution (using Microsolft Visual
Studio 2005)
the projects ara both native C++.

i've already added a reffrence from projectB into projectA.

i've got a function in projectA:
mainClass.cpp:
int main ()
{
int i = 0;
// i want to use function from project B like this:
// i = functionFromProjectB (10);
return i;
}


and in project B:
fileX.cpp:
int functionFromProjectB (int i)
{
return i * 4;
}



i know, the example is a little stange but it may be usefull to explain
my problem.

my question is how to do this or is this a .NET functionality and not
possible with native C++ projects.

Hi,

References are only useful for .NET projects.
If the second project is a library project, simply make it a dependency
of your other project and include the appropriate header files.

If the projects are not related in that way, you can simply add the
appropriate cpp file to your project.
That way the file gets compiled twice.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top