C++ :: Implement Member Functions Of Class Function - Failing To Get Input

Aug 17, 2013

I am supposed to implement the member functions of class Person.

class Person {
public:
Person();
Person(string pname, int page);
void get_name() const;
void get_age() const;

[Code] ....

The code I wrote is below. Where I am struggling is the program does not allow me to input age. Therefore, I cannot test if my temp for age works. It automatically defaults to 0 because it hasn't taken input. Here is my code:

// Program Title: Person function
// Program Description: The program prompts the user for first and last name and age.
// It then prints the output that was provided by the user.

#include<iostream>
#include<string>
using namespace std;
class Person {

[Code] .....

View 13 Replies


ADVERTISEMENT

C++ :: Where To Put Non Class Member Functions

Sep 27, 2013

If you are doing some big program, usually, how do you organize the files? Put the class and its member in head file, but where to declare non member functions and where to define them? I don't want to put them all in one cpp file. If not, how to make them visible to the main cpp file?

View 4 Replies View Related

C++ :: Defining Member Functions Outside Class Definition

Jan 3, 2014

#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
class Calc {

[Code] ....

when i built it, it showed the following errors:

1>------ Build started: Project: rough, Configuration: Debug Win32 ------
1> rough.cpp
1>e:c programs
ough
ough
ough.cpp(17): error C3872: '0xa0': this character is not allowed in an identifier
1>e:c programs

[Code] ....

Need sorting out the errors!!!

View 3 Replies View Related

C++ :: Class Member Functions With Pointer Parameters?

Jan 30, 2013

Here is the assignment: (3pts) Given the following class header file, write the class’ source code for each of the accessor and mutator functions listed. (How the functions have listed their parameters, varying between passing by reference and by value.) Don’t forget to comment your code – it counts!

class Album {
private:
char * artist; // band or singer’s name
char * title; // title of the album

[code]....

The input will be an array. My questions: First, am I on the right track?

When using (char * a) for a function, for example, this is passing the address of a, correct? so then *artist=a; changes what the address of a points to?

also, the functions are bool when I would expect void. Why? for all of the set_" " functions, the parameter is *... but for set_record_label it is *&. That appears to be a mistake to me. Is that right?

what is the difference between *& and * as parameters?

View 5 Replies View Related

C/C++ :: Limit Access To Class Member Functions

Feb 28, 2014

Suppose I make a class, something like having the constructor being invoked first makes sense, I don't have a problem with that. But, how could I limit access to functions until certain functions are called? Perhaps this isn't built into the language so you can't. And maybe this problem never comes up. For example if you have a set() and get() functions, if they are both public functions, there doesn't seem to be a way for the compiler at least now if set() never gets called you shouldn't call get(). I just see this as error prone if you need to use libraries, you have to know not to do it from documentation instead of something the compiler can check.

View 11 Replies View Related

C++ :: Accessing Private And Protected Member Functions Of Class?

Mar 30, 2013

how to access the private and protected member functions of the class.....

View 5 Replies View Related

C/C++ :: How To Call Member Functions With Template Based Class

Sep 27, 2014

This week we are learning to use templates, and I don't understand how to call my member functions with my template based class. I tried the standard convention of calling member functions, but I keep getting an error saying name following"::" must be a class or namespace name. I'm thinking my problem lies with my typename T, but I am unsure. Line 16 is where I am getting tripped up.

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
template<class T>
T Set
{
public:

[Code]...

View 2 Replies View Related

C++ :: Singleton Base Class - How To Implement GetInstance Function

Aug 20, 2014

I'm playing with the idea of a singleton base class, but I'm having an issue with how to implement the GetInstance() function in the base class. Since I'm trying to make this ridiculously simple for the child, I'd like to handle that in the base.

class Singleton {
private:
static Singleton* instance;
Singleton() { Construct(); } // Private to avoid other instances

[Code] .....

It would be easy to use like so:

class Hello : public Singleton {
private:
std::string hello;
void Construct() { hello = "hello"; }
public:
std::string GetHello() const { return hello; }
};

Then the instance would be handled like so:
std::cout << Hello::GetInstance()->GetHello();

View 12 Replies View Related

C++ :: Member Function In Derived Class Call Same Function From Its Base Class?

Sep 18, 2013

How can a member function in my derived class call the same function from its base class?

View 1 Replies View Related

C++ :: Creating Stand Alone Function That Works With Member Functions?

Nov 1, 2014

I was able to get this program running. Now I working on taking one of my member functions and turning it into a standalone function. I choose the create_board() function. Yet, if I declare it in my header file or my main.cpp it cant access any info from the original member functions?

main.cpp
#include "ticTacToe.h"
#include <iostream>
#include <limits>

[Code]....

View 2 Replies View Related

C++ :: Using Member Function Of A Class In Another Class And Relate It To Object In Int Main

Aug 21, 2013

I am writing a program which is using SDL library. I have two different classes which one of them is Timer Class and the other is EventHandling Class.

I need to use some member functions and variables of Timer in some Eventhandling Class member functions, Although I want to define an object of Timer in int main {} and relate it to its member function that has been used in Eventhandling member function in order that it becomes easier to handle it, I mean that I want to have for example two objects of timer and two objects of Eventhandling class for two different users.

I do not know how to relate an object of a class from int main{} to its member function which is being used in another class member function.

Lets have it as a sample code:

class Timer {
private:
int x;

public:
Timer();
get_X();
start_X();

[Code] ....

View 4 Replies View Related

C++ :: Calling Derived Class Functions In A Function With Parameter Of Base Class

Mar 30, 2013

Say I have 3 classes:

class Player {
public:
virtual func1();

[code]....

Say in my main class, I have a function fight(Player p1, Player p2) and I would like to do something like this in the fight function, given that p1 is the human and p2 is the computer:

//function fight()
fight(Player p1, Player p2) {
p1.func2();
}
//using function fight()
fight(human, computer);

When I compile the program, I got this: error: ‘class Player’ has no member named 'func2()' What can I do to allow p1 to call func2 inside fight()? I'm not allowed to use pointers as the parameter for fight() and have to use the signature fight(Player p1, Player p2).

View 6 Replies View Related

C# :: Error / Does Not Implement Interface Member

Jan 19, 2015

Below is a snippet of a class I am working on. My head is swimming, but I cannot understand why I am seeing the following error:

Quote

Error1 does not implement interface member 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'Medication.cs1011

View 7 Replies View Related

C :: Passing String To Function (strtoull) Failing

Sep 30, 2013

I have a code in which I am passing string "5368709120" to function strtoull() and it should had returned me number 5368709120 but instead it returns me 1073741824 which is incorrect.

What may be the possible cause of this and how to rectify it?

Code:
typedef unsigned long long
ULL_Type;
char *quotaStr = "5368709120";
ULL_Type quota;
quota = strtoull(quotaStr, NULL, 10);

View 3 Replies View Related

C++ :: Using Non-function Member Into A Class

Oct 21, 2013

I mount a function (parameter - numeric vector; returns a string). However, this same function is used in several classes. To avoid that I keep duplicating the same code within these classes there is a way to do that as the code below?

std::string func( const vector<int> vec ) {
//processamento
return result;
} class A {

[Code] ....

View 6 Replies View Related

C++ ::  member Function Of Class

Jun 16, 2013

whether i can define a member function inside a class or not in C++. Is the following code is legal?

#include<iostream> using namespace std;
class adder {
private:
int a;
int b;
int c;
int answer;
public:

[code]....

View 6 Replies View Related

C++ :: Template Function As Member Of Class

Apr 15, 2014

I want to have a template function that is a member of a class. Is this possible? This code snippet is how I would think the syntax would go, although it doesn't compile. How would I achieve the same effect?

Code:
class myclass {
public:
int member ;
} ;
template <typename T> void myclass::func( T& arg )

[Code] .....

View 4 Replies View Related

C++ :: Base Class Member Function

Apr 9, 2014

I have encountered following lines in base class and I do not comprehend its meaning of "= 0" at the end of the member functions;

distance_list intersect(ray & r) = 0;
appearance get_appearance(vector & pt) = 0;

where distance_list is a list of doubles and appearance is properties.

In general, what does this "equal sign and 0 " mean for the member functions in the base class?

View 3 Replies View Related

C++ :: Class Has No Member Named Function?

May 19, 2012

I keep getting an error saying ui.h:30: error: 'class BTree<Word>' has no member named 'prntInOrder'
I have no line 30 in my ui.h but if i count the lines from the .cpp as if they were attached to the .h i find the call to the BTree printInOrder()

here is my ui.h

Code:
#pragma once
#include "btree.h"
#include <fstream>
#include <iostream>
using namespace std;

[Code].....

As you can see the printInOrder() function is there so would it not see it?

Error:

Code:
ui.h: In member function 'void UI::go(std::string)':
ui.h:30: error: 'class BTree<Word>' has no member named 'printInOrder'

View 6 Replies View Related

C++ :: Increment Member Function In Date Class

Feb 10, 2015

I have a class I am building called date and I've built all my functions to run and done all the necessary error checking in each function. However, my last and final function I have to write is where the # of days passed in as a parameter and then I have to increment the days by that many. And if the user does not increment any days at all in the parameter and leaves it blank, then it automatically increments by one day. I am having trouble with this. So for example if the user was to do this:

Date d1(10, 31, 1998); // Oct 31, 1998
Date d2(6, 29, 1950);// June 29, 1950

d1.Increment(); // d1 is now Nov 1, 1998
d2.Increment(5);// d2 is now July 4, 1950

The function starts out looking like this

void Date::Increment(int numDays = 1) {
}

I know I have to use a for loop to accomplish this. I just don't know how to get it to where the days passed in will go to the next month and then days passed in would go to the next year.

View 2 Replies View Related

C++ :: Function Pointer To Non-static Class Member

Aug 19, 2014

I have the following problem: I am using NLOpt for optimization. The API provides functions to set the objective. This is done as follows:

double objective(const vector<double> &x, vector<double> &grad, void *data)
{
return x[1]*x[0];
}
int main(){
nlopt::opt opti(nlopt::LD_MMA,2);
opti.set_min_objective(objective,NULL);
vector<double> x(2);

[Code]....

Now I want to make the function objective a member of a class:

class Foo {
public:
double objective(...){..}
};

How can I give this method to opti.optimize? If I make objective static I can use

opti.optimize(Foo::objective,NULL);

but I do not want to have a static member. Is it possible to create an object of type Foo and give it to opti.optimize?

View 1 Replies View Related

C++ :: Templatizing A Function Based On Class Member?

Mar 26, 2014

Some background: I have a class, A, with members, B and C and D; I also have an array of A objects; I want to be able to have a function which takes said array and performs a certain calculation on either the B, C, or D members of each of the A objects, depending upon certain circumstances; I want to perform the same calculation regardless of which member is to be used in said calculation, such as always assigning the value 3 or multiplying the member's value by a cofactor of some sort.

My question, therefore, is: how I might do this using only one function be it a template or not?

View 1 Replies View Related

C/C++ :: Pointing Variable To A Member Function Outside A Class

Apr 13, 2012

In C++, how do i call a method member of class A from a class B, using a pointer. By the way Class A and B are of different types.

I read that when a pointer is pointing to member function it can only point member functions within the class. But how can i point to a member function outside the class.?????

for example

class A {
public:
int add(int x) {
return x+x;

[Code] .....

View 1 Replies View Related

Visual C++ :: Exporting Class Or Member Function?

Oct 2, 2012

Usually we use the following statements to export a class or member functions,

Code:
#ifdef DLLMICRO
#define DLLIO __declspec(dllexport)
#else
#define DLLIO __declspec(dllimport)
#endif

I understand that the files using the exported class or function need to call this class or function with dllimport and the file containing the exported class or function needs to call this class or function with dllexport. But I tried to use __declspec(dllexport) only instead of the statements above. It still works. Is there anything I am missing?Why'd we have to switch between dllexport and dllimport?

View 12 Replies View Related

C++ :: Inheritance - Class Base Has No Member Function

Jan 16, 2014

I have a simple question about inheritance. Consider the following code:

Code:
Class Base {
int type;
Base(){};
};
Class Derived1 : public Base

[Code] ....

I get the following error: Class "Base" has no member "Function1";

That makes sense - as Base has not declared Function1. But how can I loop through a vector of Bases, and then if the object is of type Derived1, call the function Function1?

View 11 Replies View Related

C :: Structs - Implement In With Pointers And Functions

Feb 23, 2013

I have a struct and I want to implement in with pointers and functions.

What is the corect syntax? For example:

Code:
typedef struct XYZ
{

int x;
int y;
int z;
}XYZ_t;

int func( using the XYZ_t struct)

[Code] .....

View 5 Replies View Related







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