C++ :: Ostream Reference As A Member Function

Nov 28, 2013

I have a class called Point that has functions for getting and setting x, y, and z coords., distance, and midpoint. I need to write a function that prints the class and must use ostream & displayPoint( ostream & ); as the prototype. I did some googling and came up with

std::ostream& Point::displayPoint(std::ostream& out)
{
out << "(" << out.getx() << ", " << out.gety() << ", " << out.getz();
return out;
}

in order to print (x, y, z).
My IDE (Xcode) says "No member named 'getx' in std::__1::basic_ostream<char>"

I don't understand much about ostream reference

View 1 Replies


ADVERTISEMENT

C++ :: Undefined Reference Error When Accessing Static Variable Inside Member Function

Feb 10, 2013

I am modifying a set of static variables inside of the class's member function. The static variables are private. An example of what I'm doing is as below,

utilities.h
-----------
class utilities {
private:
static int num_nodes;

public:
void parse_details(char* );

[Code] ....

I get a compilation error in the function void utilities::parse_details(char* filename)

which says: undefined reference to `utilities::num_nodes'

compiler: g++

View 2 Replies View Related

Visual C++ :: Access Member Function From Non-member Function In Same CPP File?

Dec 16, 2012

In my MFC, CMyPorpertyPageDlg is derived from CPropertyPage. How to access its member function from a nonmember function in the same CPP file?.

void Non_Member_Get_PorpertyPage()
{
CMyPorpertyPageDlg* pPageDlg = ....
}

View 4 Replies View Related

C++ :: Store Reference To Const Object In Class As A Member Variable?

May 27, 2014

i want to store reference to a const object in my class as a member variable, as follow:

I basically want a readonly reference to |Data| in Device object.

Code:

class Device {
Device(const QList<QSharedPointer<Data>> & dataList) : _listRef(dataList) {
} protected:
const QList<QSharedPointer<Data>> & _listRef;
}

This does not allow me to initialize _listRef as something like NULL when it is not applicable.Also, i must change all my constructors and its child class to include an initialization of _listRef!!

What is the alternative? Is pointer the nearest? which of the following should be used?

Code:
const QList<QSharedPointer<Data>> * _listRef;
or
const QList<QSharedPointer<Data>> *const _listRef;
or
const QSharedPointer<QList<QSharedPointer<Data>>> _listRef; ????

View 7 Replies View Related

C++ :: Non-static Member Reference Must Be Made Relative To A Specific Object

Mar 4, 2012

Code:
class A
{
std::map<std::string, Unit*> aMap;
class B

[Code] .....

This code snippet results in "A non-static member reference must be made relative to a specific object". When I make callA() static, this error goes away, but there is problem with aMap.

View 2 Replies View Related

C++ :: Call To Member Function X Is Ambiguous - Overloaded Member From Header File

Feb 23, 2014

I get the following error in XCode whenever I try to access the member I created 'randomGen' in a separate class in a different header file. I have made sure to include the header file and have tried to access it through an object.

This is the code I enter when trying to access the method from randomiser.h in main.cpp. It is also an overloaded function with doubles and integers:

RandomG randomiser;
randomiser.randomGen(); // 'Call to member function 'randomGen' is ambiguous'

This is the code inside randomiser.h:

#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
class RandomG {

[Code] ....

This is the error inside xcode: [URL] ....

I have tried seperating the code for the functions in another class (main.cpp) and then running and it seems to works, so I'm not sure why I can't put everything in the .h file and then access it?

I would like it in a seperate file so it doesn't clutter my main. I am writing a game with SDL so that might be confusing and I would like the window to have a random title and other random properties, so it would be easier to use a function.

View 3 Replies View Related

C++ :: Call Member Function Inside Another Member Function?

Mar 21, 2013

If I wanted to call a member function inside another member function, how would I do that, if it's possible?

For example, if I have Find(int key) defined already and wanted to call it while i was overloading operator+.

View 2 Replies View Related

C++ :: Print Score In SDL With OpenGL Using Ostream?

Mar 5, 2013

I am using the following code to print in SDL screen

SDL_GL_RenderText( timer, font, color, &position);
sprintf(timer," Time : %d",time);

to print in SDL screen(used with opengl) , i am doing project on C++, as "sprintf" is C style function , so i can't do like this , i am trying to use" ostringstream" , but i am not sure how to use it.

View 1 Replies View Related

C++ :: Difference Between Ofstream And Ostream Operators

Aug 17, 2014

I'm trying to overload an operator << so that it prints to a .txt file. Would these two codes basically do the same thing? If so, which one is the more efficient one to use?

ofstream& operator<<(ofstream& fout, const Grid& g);

ostream& operator<<(ostream & out, const Grid& g);

View 2 Replies View Related

C++ :: Non Constant Member Function Being Called Inside Constant Member Function?

Dec 28, 2012

#include <iostream>
class Hello {
public:
void Test() {

[Code].....

As i know a non-constant member function cant be called inside a constant member function but how the above code has been compiled successfully and giving the expected result .

View 5 Replies View Related

C++ :: Store A Reference Variable As Member Variable Of Interface Object

May 1, 2013

I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.

LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).

I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip

I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.

View 11 Replies View Related

C/C++ :: Get Fstream / Ostream / Ifstream To Save Ints Then Load Them

Jun 5, 2014

I have been trying to figure this out for a text based game. Lets say your money is 500. Then you save your game, but when you start the game the starting is 50, so when you load it, you still have 500 money, I tried lots of test, and im having trouble?

View 10 Replies View Related

C++ :: Giving One Line Command That Prints Lots Of Lines - Ostream?

Nov 9, 2012

I'm using cout to print lots of lines. But i want to put together them in one variable etc. Then , i want to print it. I think i can do it with ostream but I cant do it . Is there any example use of ostream.

I want to use it such that:
x<< "hello" << endl;
x<< "mike" << endl;
x<< "how " << endl;
x<< "are" << endl;
x<< "you" << endl;
cout << x;

Will print

hello
mike
how
are
you

How can i do it?

View 5 Replies View Related

C++ :: Undefined Reference To A Function

Jan 19, 2013

The error is this:

#include <iostream>
using namespace std;
void add(int s);
void subtract(int d);
void multiply(int p);
void divide(int q);

[Code] .....

View 2 Replies View Related

C++ :: Undefined Reference To A Function?

Nov 23, 2013

I'm making a program that's essentially a Text-Based Fire Emblem game; it runs calculations and rolls dice and has all sorts of Goodies. However, I have hit a block to the tune of

#ifndef ITEM_H
#define ITEM_H
class Item
{

[Code]....

Up Until I called up a Sword object, it worked fine. But when I compiled it, I got an Undefined Reference to Item::Item() error in Line 8 of Weapon.cpp.

View 2 Replies View Related

C++ :: Returning By Reference From Function

Feb 15, 2015

#include<iostream>
using namespace std;
int &fun() {
int x = 10;
return x;
}
int main() {
fun() = 30;
cout << fun();
return 0;
}

The code outputs 10.

Shouldn't it show an error because x is created locally on stack and gets destroyed on function return?

View 1 Replies View Related

C++ :: Undefined Reference To (function Name)

Oct 2, 2014

Everything seems to be in order and I know my code still has mistakes. I'm just trying to get it to compile and it won't allow it. I've narrowed it down to when I call the functions in main but beyond that I have no clue.

#include <iostream>
#include <cstring>
using namespace std;
void getSize(int num);
void getSpace(int num, int ptr);
void inputData();
void printData();
void destroy();
const int BIG_NUMBER = 100;

[code]....

View 4 Replies View Related

C++ :: Undefined Reference To Function?

Oct 24, 2013

So I have a really strange problem occurring...

First, here are the files I'm using:

//pa4.cpp wirtten by Syd Frederick
#include<iostream>
#include<string>
#include<fstream>

[Code].....

When compiling I'm getting a strange error that says :

/tmp/ccdt0Bf9.o: In function `main':
pa4.cpp:(.text+0x1c): undefined reference to `synopsis()'
pa4.cpp:(.text+0x1e7): undefined reference to `execute(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status

View 2 Replies View Related

C++ :: Displaying Function From Reference?

Aug 29, 2013

Having a little trouble getting my function to display the results. I got my getNumber function working and I know I can't use return to return multiple values so I created a function that would display my results but I am a little lost on how I get the results from one function to another.

#include <iostream>
#include <array>
#include <iomanip>
using namespace std;
void printResult(int, int);
void getNumber(int &, int &);
void printResults (int, int){
int n, n1;

[code].....

View 13 Replies View Related

C++ :: Using Pointers Instead Of Reference Variables In Function

Mar 26, 2013

The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.

int doSomething(int &x, int &y)
{
int temp =x;
x = y * 10;
y = temp * 10;
return x + y;
}

I understand how to covert the reference variables to pointers, however I am stuck on this error. Either I get the error listed in the title or (with a few changes) the error "invalid conversion from 'int' to 'int*'"

What am I doing incorrectly?

#include <iostream>
using namespace std;

int doSomething(int*, int*);

int main(){
int X, Y, result;

[Code] ....

I have multiplied both x and y by 10 and then added them together!

Here is the result " //I really didn't know how else to use the "doSomething" function in a meaningful way. So... I just stated what the function does.

<< result << ".
";
system("PAUSE");
return 0;
}
int doSomthing(int *x, int *y)

[Code] .....

View 1 Replies View Related

C++ :: Attempting To Reference A Deleted Function

Feb 20, 2015

Been away from c++ for a few months now (apart from answering a few questions on this site). I was trying to see if I could do a simple program using just my memory that involved unique_ptr's, but getting an error:

"attempting to reference a deleted function". I thought that by getting a reference to my pointer would not invoke a copy constructor but i'm clearly wrong.

Here's the code:

#include <iostream>
#include <memory>
#include <vector>
class Shape {
public:
virtual void Draw() = 0;

[Code] ....

View 5 Replies View Related

C++ :: Reference To A String In Function Parameters

Feb 22, 2015

So I was reading my book and it listed this piece of code. The first piece of code is in the book and the 2nd is just my test on the piece of code. I am curious as to why in the functions parameters there is a reference to aString. I've noticed that removing it has no affect on the outcome of the code.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isPalindrome (string & aString) {

[Code] ....

View 2 Replies View Related

C++ :: Undefined Reference To Template Function

Oct 21, 2013

I am coding a RTS game but I cant compile my dataLoader function. It gives that errors when want to call it:

//Window size
int width;
int height;
if( !dataLoader<int>( width, "settings/resolution.txt", "width" ) || !dataLoader<int>( height, "settings/resolution.txt", "height" ) )

[Code] ....

View 7 Replies View Related

C++ :: Function Passed By Pointers Or Reference?

Sep 28, 2014

I am going to read some codes about image processing and I need to understand functions like this one below?

BOOL Trans_Geo_Affine(CImage *pImgSrc, CImage *pImgDst, BOOL bMatrix,
BOOL bHvInversed, double fScale_xx, double fFlex_xy, double fSkew_yx,
double fRotate_yy, double fTx, double fTy, int nInterpolation, BOOL bResize, BYTE cFill)

[URL]

two parameters, CImage *pImgSrc and CImage *pImgDst. I think they are class pointers and the function is passed by reference. What should I learn to understand this function and its parameters? How should I use this function? how to use the function with two parameters CImage *pImgSrc and CImage *pImgDst.

View 11 Replies View Related

C++ :: Return Reference For Derived Function

Jun 3, 2014

I dont know what kind of return reference I have to put to override the following derived member function in C++:

virtual SEntityPhysicalizeParams& GetPhysicsParams() override {return ???;}

The place where I should put the return value is marked with ???. SEntityPhysicalizeParams is a struct from another header from which I dont have access to it's source file.

I tried several things but noone seemed to work out and keep getting me either error "function must return a value" or "initial value of reference to non-const must be an lValue".

Here is SEntityPhysicalize where my function is refering to:

struct SEntityPhysicalizeParams
{///////////////////////////////////////////////////////////////////
SEntityPhysicalizeParams() : type(0),density(-1),mass(-1),nSlot(-1),nFlagsOR(0),nFlagsAND(UINT_MAX),
pAttachToEntity(NULL),nAttachToPart(-1),fStiffnessScale(0), bCopyJointVelocities(false),
pParticle(NULL),pBuoyancy(NULL),pPlayerDimensions(NULL),pPlayerDynamics(NULL),
pCar(NULL),pAreaDef(NULL),nLod(0),szPropsOverride(0) {};

[Code] ....

View 8 Replies View Related

C++ :: Undefined Reference To Function Error

Nov 19, 2013

I am currently working on a code, but I keep getting a error as follows:

[Linker error] undefined reference to 'getHoursOfTheWeek(double)'
[Linker error] undefined reference to 'getGrossPay(double)'
[Linker error] undefined reference to 'getStateTax(double)'
[Linker error] undefined reference to 'getFederalTax(double)'
[Linker error] undefined reference to 'getFICA(double)'
[Linker error] undefined reference to 'getWithHoldingAmount(double)'

I have been trying to debug this error for hours and I am completely stumped....

//BEGIN
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string getUserName();
double getPayRate();

[Code] .....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved