Questions tagged [function-declaration]

A function declaration is the process of describing only the return type, argument types, and name of a function. This is required in some programming languages to use functions that were defined at a later point in the code or in another file. Use this tag for questions that pertain to or problems caused by forward declaring functions in languages that support or require doing so.

549 questions
4
votes
3 answers

struct in separate header file causing problems in C++

I have a struct Tree that is defined inside Class Parser. I have methods defined in Parser that take Tree as input. void Parser::InputTree(const Tree& input) { //uses data from Tree } Everything seemed to be working fine. But then I needed to use…
user592748
  • 1,194
  • 3
  • 21
  • 45
4
votes
3 answers

c++ class with constructor definition but no code where it is implemented?

I have the following class in a single .h file: class MyClass { protected: MyClass(); ~MyClass(); private: MyClass(const MyClass&); MyClass& operator=(const MyClass&); }; inline MyClass::MyClass() { } inline…
m4l490n
  • 1,592
  • 2
  • 25
  • 46
4
votes
2 answers

Why would I assign a function declaration to a named variable?

Edit: it's NOT an assignment of a function declaration to a named variable - check the accepted answer. Leaving title as it is because other people might make the same error as me. While reading Paul Irish's infinitescroll jquery plugin code, I…
timkg
  • 1,773
  • 2
  • 14
  • 12
4
votes
3 answers

Does this line declare a function? C++

I was reading litb's question about SFINAE here and I was wondering exactly what his code is declaring. A simpler (without the templates) example is below: int (&a())[2]; What exactly is that declaring? What is the role of the &? To add to my…
GRB
  • 1,515
  • 2
  • 11
  • 10
3
votes
2 answers

How do browsers handle multiple function declarations with the same name?

How do browsers handle multiple function declarations with the same name? Specific test case is below - NOTE: I know this does not make sense to allow a server script to create more than one function declaration with the same name, but I am curious…
3
votes
4 answers

position of virtual keyword in function declaration

Does it make any difference whether I place the virtual keyword in a function declaration before or after the return value type? virtual void DoSomething() = 0; void virtual DoSomething() = 0; Found the void virtual syntax while refactoring some…
Ronald McBean
  • 1,417
  • 2
  • 14
  • 27
3
votes
3 answers

Explain the difference in these function pointer declarations

Please highlight the difference between the following function declarations: void (*p) (void *a[], int n) void *(*p[]) (void *a, int n)
vikaspraj
  • 1,003
  • 1
  • 9
  • 10
3
votes
4 answers

Inline function prototype vs regular declaration vs prototype

What's the difference between inline function and then main like so: inline double cube(double side) { return side * side * side; } int main( ) { cube(5); } vs just declaring a function regularly like: double cube(double side) { return…
lorenzoid
  • 1,812
  • 10
  • 33
  • 51
3
votes
5 answers

Why is char** argv same as char* argv[]

So I have read that behind the scenes when passing an array in a function the compiler turns int myArray(int arr[]) into int myArray(int *arr) Also an array most of the times decays to a pointer, for example arr[0] is the same as (arr + …
3
votes
5 answers

Data manipulation inside a function in "C"

Here's something I don't understand. Maybe someone can shed some light on it. I know that the standard method for data manipulation is passing a reference to a function and changing the data in the function. Like this: #include #include…
3
votes
1 answer

Why were parentheses disambiguated as a function declaration with std::istream_iterator?

auto queue = [](string str) { istringstream ss(str); //std::copy(std::istream_iterator(ss), // std::istream_iterator(), // std::ostream_iterator(std::cout, " ")); //deque
isudfv
  • 179
  • 1
  • 9
3
votes
2 answers

Why this code works ? memcpy on a constant array

The parameters for memcpy are memcpy(void *_Dst, const void *_Src, size_t _Size) But with the following code, I pass a constant array as parameter '_Src' and it still copy the content of the array into the destination, even though I didn't pass a…
subski
  • 57
  • 7
3
votes
1 answer

strcpy through array of strings passed to a function?

Long story short, I'm making this 3D OpenGL builder game. The details don't matter much, but here is my problem. I have this array of strings: char building_category_names_UPPER_CASE[][30] = { "NOTHING", "WAREHOUSE", "PROCESSING PLANT", "FACTORY",…
3
votes
3 answers

Why using declaration is needed when an overload is deleted

Why do I have to reintroduce the name of a function having some of its overloads deleted ? #include struct A { void f(int) {} void f(double) {} void f(const std::string&) {} }; struct B : public A { using A::f; // needed…
SR_
  • 874
  • 13
  • 31
3
votes
3 answers

Defining a C function that takes a 2D array with variables for dimension sizes

Edit: Turns out the compiler I'm using doesn't support variable length arrays so I have no way of achieving the notation I desire using MSVC I have a function which takes in an array of strings and a query string, and returns the index of the…