LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find the scope/definitions of a class/methods ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-the-scope-definitions-of-a-class-methods-788836/)

mq15 02-13-2010 01:08 AM

how to find the scope/definitions of a class/methods ?
 
In Windows environment when I used Borlan for C/C++ compilation, I was used to find the the scope/definitions of the methods/classes by pressing
Code:

ctrl + F1
when the cursor was hovering on that method/class. How can I find the scopes/definitions in the GNU/Linux?

Code:

//atoi.cc
#include <iostream>

main(int argc, char* argv[]) {
float var_float = atof(argv[0]);
int var_int = atoi(argv[1]);
printf("var_float is %2.1f\nvar_int is %d\n",var_float,var_int);
}

Code:

[mq15@localhost c-c++_files]$ c++ atoi.cc -o atoi
atoi.cc: In function ‘int main(int, char**)’:
atoi.cc:7: error: ‘atof’ was not declared in this scope
atoi.cc:8: error: ‘atoi’ was not declared in this scope

Code:

[mq15@localhost c-c++_files]$ c++ --version
c++ (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Best Regards

carbonfiber 02-13-2010 01:54 AM

Code:

$ man atof
$ man atoi


mq15 02-13-2010 03:46 AM

two more confusions
 
Thanks.

1.1 If man shows manual of bash commands/utilities, how it is showing the manual of a c/c++ method i.e. atof()?
1.2 If atof() is not a c/c++ method, but it is a bash command/utility, then how we can use a bash command/utility i.e. atof() in a .cpp source file?

2. I have included stdlib.h and atoi.cpp is compiled with no errors, yet the result is not what I expect:
Code:

[mq15@localhost c-c++_files]$ ./atoi 5.4 6
var_float is 0.0
var_int is 5



What I expect is:
Code:

[mq15@localhost c-c++_files]$ ./atoi 5.4 6
var_float is 5.4
var_int is 5



See the cource code of atoi in post#1
Best Regards

carbonfiber 02-13-2010 04:11 AM

1.1: Magic

1.2: atof is neither a c/c++ class/method nor a bash command/utility

2.0: Of course the result is not what you expect. This is a consequence of the fact that you do not know what argv[0] is supposed to be.

P.S.: Conduct the following experiment: write a C program which prints argv[i] (0 <= i < argc) on separate lines.

mq15 02-13-2010 04:43 AM

1.1 Still not satisfied :(
1.2 Then what atof actually is ?
2.0 Got it now. argv[0] holds the string the file was invoked with, in the terminal.
argv[1], argv[2]...argv[i] are supposed to be string values.

Code:

//arguments.cc
#include <iostream>
#include <stdlib.h>

main(int argc, char* argv[]) {

for(int i=0; i< argc; i++)
        printf("arg[%d] = %s\n",i,argv[i]);
}

Code:

[mq15@localhost c-c++_files]$ ./arguments str 5 6.7
arg[0] = ./arguments
arg[1] = str
arg[2] = 5
arg[3] = 6.7

The main problem is still unsolved: How to find the scope/definition of c++ classes/methods???
For example if I use
Code:

cout<<"Hello World";
, I get
Code:

‘cout’ was not declared in this scope
and doing man cout shows No manual entry for cout

nivantha 03-12-2010 09:47 AM

Put this before the main funciton in your c++ code. You'll be able to compile the C++ code

using namespace std;


All times are GMT -5. The time now is 05:16 AM.