im really new to c++, i started last week... i wonder how to run a fnunction. i mean if i have a function named like
<
int myFunction()
{
cout<<"A function";
}
>
how do i run it?
and how do i make a windows application???
Printable View
im really new to c++, i started last week... i wonder how to run a fnunction. i mean if i have a function named like
<
int myFunction()
{
cout<<"A function";
}
>
how do i run it?
and how do i make a windows application???
You need to call it in main(); take a look at the tutorials on this site for some basics.
Windows programming is a very complex API, and I would suggest you get down C++ pretty well before starting.
okay, for fxns, you may want to consult the tutorials and faq for it.
same thing with windows programming, windows programming forum, google, and FAQ.
if you are new to c++, have you had programming experience before, I'm inclined to believe no because you are wondering how to call a fxn. if you are new to programming in general, you would want to learn concepts and other things before thinking about win32api and games.
but for a fxn, ex. a fxn to cout something would be like the following:
Code:void function() {
std::cout << "A function" << std::endl;
}
int main() {
function();
return 0;
}
for very very short functions use "inline" it makes it go faster...but you cant tell the difference because instead of calling the function it places the body of the function in where it is being called....hehe
Well ive programmed in javascript before, but im not an expert.. ive tried writing
<code>
#include <iostream>
int main()
{
function();
}
int function()
{
}
</code> but it doesnt work... maybe i just forgot that semicolon
Problem here is that the compiler has never heard of your function before you call it in main.
Put
int function();
above main and see if that works.
Okay ive tried the following code:
im using dev-c++4 and it says "implicit declaration of function 'int function(...)'"Code:<code>
#include <iostream>
int main()
{
function();
return 0;
}
int function()
{
std::cout << "A function" << std::endl;
return 0;
}
</code>
Try thatCode:#include <iostream>
int function ();
int main()
{
function();
return 0;
}
int function()
{
std::cout << "A function" << std::endl;
return 0;
}
power to non-prototyped functions!
Code:#include <iostream>
int function()
{
std::cout << "A function" << std::endl;
return 0;
}
int main()
{
function();
return 0;
}
you either have to prototype the fxn or place the whole fxn above main. fxns can only see what is above them.
I am ok at C++... I made a VERY simple program to let you see how some basic things work, if you already don't know how. I havent error checked it yet, and I know that the char does not work but you get the idea. :o