You can check it here: [URL] The output is correct, but in my machine with C++11, MinGW 4.8 (64 bit in a 64bit-Windows8), the output is incorrect. Why?
If you want more specific info, the problem is that I use input, I think. I use std::getline(std::cin, some_string).
I have observed that inline functions can not be prototyped. example:
.cpp file:
inline void whatever() { cout<< "this is inline"<< endl; }
.h file, prototype inline void whatever(); //would ask for a definition
Because of this, I have have just made functions that are used in only 1 .cpp file (ever) inlined, to make it more efficient (and it has demonstrated that it is more efficient). It's worked out fine so far, but what about the scope of the definition??
Since an inline function is like a templated function, in that it can't be prototyped, how are name conflicts resolved, and what is the best practice for writing inline functions??
Example of a conflict:
//in some arbitrary header... void do_somthing(); //in .cpp file that inlcudes the header... inline void do_somthing() { cout<< "I'm doing somthing!!"<< endl; } int main() { do_somthing(); //which one?? it compiles fine though!! return 0; }
This: "The compiler may not always be able to insert the code for a function inline (such as with recursive functions or functions for which you have obtained an address), but generally, it will work."
For a function inline why wont it work for a recursive function or a function for which you have obtained an address?
I have some functions inlined using the inline function prefix. If the function is called from outside the file (so a seperate psp-gcc -O3 ... filename.c filename.o compile command, when only the function is changed), will the other files be updated too? (I'm using the pspsdk toolchain).
Example:
max.c inline byte max(byte a, byte b) { return a>b?a:b; } use1.c void use1() { if (max(1,2)==0)
[Code] ....
If I compile this, next change the max function and recompile using make (the compiler only takes the changed max.c->max.o file, next links them together) will use1.c&use2.c be updated with the new max.c function?
I have a template class which defines a few heavy methods. For now, they are defined in the same .h file as the class definition, but i`d like to have them in a separate .cpp file.
A situation i find you describe in the FAQs arises: [URL] ....
Problem: the export keyword has been deprecated in c++0x, if i recall correctly, and has never been implemented in any of the compilers i am using (msvc, gcc).
#Including the the .cpp file after the class definition (as described in the second post of the FAQ) works.
another question: i have methods that dont use any template code. Can i somehow declare them as such? (more of an esthecial question, which would make it easier to distinguish between template and non.template code).
i need a function that will work for both dynamic and static implementations of a function to get the transverse of a matrix. so far, i have this
Code:
matrix transpose(matrix m) { int row, col; row = m.com_dim; col= m.row_dim; }
[code]....
this works well with my static implementation, but when i try it in dynamic it gives me errors. the function has to be the same for both dynamic and static implementation
i want to use a class to print data stored as vector or array with different data types. i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns. so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file
these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions
i want to use a class to print data stored as vector or array with different data types.
i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns.so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class / i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions.
I'm trying to implement a simple template array class, but when i came into the operator< i actually have to use a template :
my code is something like :
template<typename _Type, std::size_t _Size> class array { public :
[Code] ......
but i am having an error of shadows template param 'class _Type' is it w/ the name conflict between the array template parameter and the function template parameter ?
where 'g()' returns an object of the element type. However, the compiler is claiming, no matter how I write a call to the overload, the original template is selected and/or the overload is invalid, depending on the various ways I attempt to write said overload.
I am assigned this program by my instructor and he wants me to convert the function to function template. I do not know how to do that. How to get good grades in final.
i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example
Code: int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5} but if i have this one
int group_id_local[max_j]={2,1,4,3}; // output should be {1,2,4,3} /* COMPARE FUNCTION FOR USING QSORT()*/ int cmpfunc (const void* a, const void* b) { if (*(int *)a < *(int *)b) return -1; if (*(int *)a > *(int *)b) return 1; return 0;
I have to do a BST project for school and I am almost there. Here is the code:
BINARY_SEARCH_TREE.cpp #include "stdafx.h" #include "genBST.h" #include <iostream> using namespace std;
[Code].....
When I run the program, it compiles correctly but does not give any output. I'm not sure what else to do. I've tried changing up the code in nodeCount(), leafCount(), NodeCount(), and LeafCount(). I've tried adding a count variable to both nodeCount() and leafCount() but that didn't work. If I fiddle with the functions, I get a whole mess of errors. Currently, the code is stable but just won't output what I want it to.
I'm having trouble with getting a sine function to work. All variables are defined earlier in the same section. I have the code in a button (where I figured it would go) but I get the following error:
WindowsFormsApplication2.Math does not contain a definition for 'Sin'
For reference, I am using Microsoft Visual Studio Express 2013, and am coding a Windows Forms Application.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
[Code] ....
I've tried other functions as well (abs, sqrt, etc.) to no avail, as Math only seems to pop up with two options: Equals and ReferenceEquals.
We have to make a function integrate to work with the other functions given. I had it working before but I would only get all -4 as my answers but only the first one should be -4. what should more or less be put in my integrate function?
void Quicksort(int info[],int left,int right){ int pivot = left + (right - left)/2;//it is the middle (will change sometimes but will end up in the middle int temp;
while(left<=right){ while(info[left] < pivot){
[Code] ....
This is my quicksort function. I have tried a lot of things but I am trying to get it to work to sort all the details I have stored in an array by there age. This is how I have entered the data.
void DataEntry(Details info[],int size){ int x; int i; i=0; cout << "How Many Entries Would You Like to add";
This function should delete each element in the list which is the same as this one typed by user. There are no errors, but function doesn't work. It deletes something, but not this element which should.
I wrote a program with function my own function which count the digits of entered number. The problem is whatever i type it shows 0 digits.Why is that?
Code: #include <iostream> using namespace std; int cikCipari (int skaitlis, int cipars); int main()
I realized a Matrix class to practice and I have a problem I can not solve! Here my problematic code:
Mtrx.h:
Code: template <class T> Mtrx::Mtrx(dim m, dim n, const bool random_constructed = false, const T min = static_cast<T>(0), const T max = static_cast<T> (10)) Mtrx.C
[Code] ...
And here the relative main section:
Code: Mtrx rand1 ( 5, 5, bool);// ok cout<<rand1<<endl;
Mtrx rand2 ( 7, 3, bool, -5, 20);// ok cout<<rand2<<endl;
Mtrx rand3 ( 7, 7, bool, 0., 15.);// compilation error: undefined reference to // "Mtrx::Mtrx<double>(unsigned long, unsigned, bool, double, double)" // collect2: error: ld returned 1 exit status
I have this class templates And This UML.I have to write this function +operator=(source: Array<ElemType, SIZE>): Array<ElemType, SIZE> but I do not know how to start the declaration / or start the function. I have to return a template but I do not know how to do it,