GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Jul-2010, 04:31
qtuutr qtuutr is offline
New Member
 
Join Date: Jul 2010
Posts: 3
qtuutr is on a distinguished road
Unhappy

Error C3861: 'sum_of': identifier not found


hello people, i'm currently new to c++ (how original) and trying to get the hang of structs and classes, I tried the following code, but it errored. Can someone explain why and preferably correct it as well?
CPP / C++ / C Code:
#include <iostream>
using namespace std;

struct Blaat{
	int a;
	int b;
	int sum;

	void do_something(){
		sum = sum_of(a, b);
	}
};

int sum_of(int a, int b){
	return a+b;
}

// the main entry point for the application is this function
int main ()
{
	Blaat blaat;
	blaat.a = 1;
	blaat.b = 2;
	blaat.do_something();
	cout << blaat.sum << endl;
	return 0;
}
thx in advance...

I am aware of the easy fix (implementing sum_off() inside the struct Blaat) but due to some structure I would like to use later on, it is far easier to have this function "out in the open", if you get what I mean.

*I'll add the error...
1>------ Build started: Project: Game Level, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:\program files\the game creators\dark gdk\tutorials\game level\game level\main.cpp(11) : error C3861: 'sum_of': identifier not found
  #2  
Old 19-Jul-2010, 06:19
qtuutr qtuutr is offline
New Member
 
Join Date: Jul 2010
Posts: 3
qtuutr is on a distinguished road

Re: please help me here


sorry for the bad title, I didn't realise it...
  #3  
Old 19-Jul-2010, 07:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,160
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: please help me here


Quote:
Originally Posted by qtuutr
...main.cpp(11) : error C3861: 'sum_of': identifier not found
The compiler must know what kind of function it is when it first encounters the use of that function.

You can give the compiler this information by declaring the function in a prototype statement. (At the movies this would be called "Previews of coming attractions.")

For example:
CPP / C++ / C Code:
.
.
.
// Prototype for the sum_of function.  Note the semicolon
int sum_of(int a, int b);

struct Blaat
{
    int a;
    int b;
    int sum;

    void do_something()
    {
        sum = sum_of(a, b);
    }
};

//Definition (implementation) of the function
int sum_of(int a, int b)
{
    return a+b;
}
.
.
.


Regards,

Dave
__________________
Sometimes I just can't help myself...
  #4  
Old 19-Jul-2010, 07:19
qtuutr qtuutr is offline
New Member
 
Join Date: Jul 2010
Posts: 3
qtuutr is on a distinguished road

Re: please help me here


Thanks, didn't realise I used the function before implementation. Thanks alot!!!
  #5  
Old 19-Jul-2010, 08:02
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,160
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: please help me here


Quote:
Originally Posted by qtuutr
Thanks, didn't realise...
That's what the compiler message was trying to tell you: it works its way down from the top to the bottom of the file (one pass). After you have seen that message a few times it will start to make sense. (I have seen it a lot of times, so I knew right away...)

After all, no one was born knowing this stuff, right?

Regards,

Dave
__________________
Sometimes I just can't help myself...
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:16.


vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.