C++ :: Can't Add A String Remembering Last Value In A Class
Jun 10, 2014
I have to compare the last value of 2 classes The 1rst is a notification class and the 2nd is a message class I have to remember the last value of each of them to compare them ( to not show message if dupplicate text in notification ) I have try to add a new string to memorize the last value in those 2 classes but that doesn't work , I always have nothing in my strings
Here are the points I have add to do it :
- Add declaration memorize strings in both xxxxx.h and yyyyy.h
- Add declaration functions SetMemo and GetMemo in both xxxxx.cpp and yyyyy.cpp
- Add functions source code SetMemo and GetMemo in both xxxxx.cpp and yyyyy.cpp
I have tested step by step :
- The SetMemo works well , it takes the value and save it in memorize string
- The GetMemo works too , take memo string and returns it but the value is empty
I use to develop with C# ... I'm not a C++ expert , maybe I forget something special in C++
View 2 Replies
ADVERTISEMENT
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
May 12, 2013
I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:
cajun/mustard
I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:
Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;
Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.
My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.
(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)
View 6 Replies
View Related
Dec 24, 2014
I wanted to create a new class object and I want to name it from a string. Something like this:
string name = "Mike";
Customers name;
//to create a new object in customer class using the name string
Is there any way to do this?
View 11 Replies
View Related
May 23, 2013
I have encountered a problem with template class. I have made a template class that converts a value into a string, and then made another template class that converts string to T if its possible. Now I need to overload >> and << operators for type T.
template<typename T>
string toString (const T &value) // convert a value into a string {
ostringstream os;
//os << value;
return os.str();
[Code] ....
View 2 Replies
View Related
Oct 8, 2014
I'm giving the replace option to my string:
void replace(string oldstring, string newstring) {
int stroldstringpos=b.find(oldstring);
b.replace(stroldstringpos,newstring.length(),newstring);
}
i have 1 error in these function that i'm confused. imagine the newstring size is more big than the oldstring, how can change the string, but only change the oldstring and add what left?
see these:
String test="hi hello world";
test.replace("hi","hello");
the result must be:
hello hello world
how can i change the replace function for it?
View 3 Replies
View Related
Dec 14, 2014
I'm new to c++, so how to print the contents of a map that contains a string and a class of integers for option 1. what formatting should I use?
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include "IPHost.h"
#include "EncryptedConnection.h"
[Code] .....
View 6 Replies
View Related
Dec 8, 2014
I have been trying to get this my class template to print out a string for me, however I am getting :
" error C679 ' No operator found which takes a right hand operand of type std:: string' "
I have tried various way to get this going however I cant get past this error. I understand that templates functions how ever i am not sure why i am not getting my string to be displayed.
#include <iostream>
#include <string.h>
using namespace std;
template<class T>
class BinaryTree {
struct Node {
[code].....
View 1 Replies
View Related
Nov 25, 2014
Is it legal in VC++ to create a class composed only of string colections. If it is how can I create it in VC++ and add it to my project?
View 6 Replies
View Related
Apr 19, 2014
I created class called students which suppose to store students names of any sizes in an arrey but when I call the display function it does not show the names.
#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
class students{
public:
string names[SIZE];
[Code] ......
View 1 Replies
View Related
Apr 28, 2013
I want to use this array as part of my class. I have tried several different angles trying to get it to work but with out success. I have been checking to see if it works by simply using "cout << dayName[3];" It is printing nothing at all. What is the proper way to initialize this array of strings?
First I tried this:
const string dayName[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
then I tried this:
const string dayName[7];
dayName[0] = "Sunday";
dayName[1] = "Monday";
dayName[2] ="Tuesday";
dayName[3] ="Wednesday";
dayName[4] ="Thursday";
dayName[5] ="Friday";
dayName[6] ="Saturday";
My implemetation file code and my header file code is here (header first):
//dayType.h, the specification file for the class dayType
#include <iostream>
#include <string>
using namespace std;
class dayType{
[Code] .....
View 4 Replies
View Related
Jul 23, 2014
class myclass{
string myarray[5];
myarray[0] = "one"; myarray[1] = "two"; myarray[2] = "three"; myarray[3] = "four";
myarray[4] = "five";
};
this works in main function but doesn't work in the class;
1. Why this methods doesn't work inside class but works in main function?
2. What is the proper way of using string array inside a class?
View 4 Replies
View Related
May 10, 2013
following code that I'm reading out of the book "The C++ Standard Library".
class C
{
public:
explicit C(const std::string & s); // explicit(!) type conversion from strings.
...
[Code].....
Now I understand that they are saying that an explicit conversion isn't allowed but what I don't understand is what explicit conversion would be happening if there was one allowed.
Specifically I don't understand the const C & elem syntax. How does this work since the collection holds strings. What would be the syntax for how this:
const C & elem
gets strings. I was thinking it was a class reference that someone how converts to a constructor function pointer or something but i'm really confused.
View 4 Replies
View Related
Sep 27, 2013
I am IT student and had a C++/C (oral + paper) exam today. One of the tasks was to write a 2D-Matrix (as the question said) class with following restrictions:
- No <string> header is allowed
- Only Dtor needs to be implemented
- No templates
- Following should be possible:
Code:
std::cout << mat1 + mat2 + "some randome string";
mat1 += mat2; So i did the following:
In Matrix.h i wrote: Code: Class Matrix{
int rows, cols;
char *arr[][];
[Code] .....
Now..this destructor made me loose some points since the Prof. said that it is not correct. The corrected version was:
Code:
Matrix::~Matrix(){
if(arr){
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
delete [] arr[i][j];
[Code] ....
Now, i agree on that error i made, but it is only in case we use the "new" keyword to reserve place dynamically for each string(for each char*). So this raised the question in my head about:
Since the following is allowed in C++
Code:
char* str1 = "hello";
char* str2 = "you";
arr[1][3] = str1;//arr[1][3] was initialized to "_" without new keyword
arr[6][0] = str2;//arr[6][0] was initialized to "_" without new keyword why would someone use the new keyword..
I mean like this:
Code:
arr[1][3] = new char*[sizeof("sometext1")+1];
arr[1][3] = "sometext1";
arr[6][0] = new char*[sizeof("sometext2")+1];
arr[6][0] = "sometextw";
What is happening internally in C++ in both the cases(with and without new keyword)?
View 11 Replies
View Related
Nov 17, 2014
Im trying to make a c++ program for a school project, and i need to store the information into binary files, but I'm having some problems trying to store a class with string members, for example:
class whatever{
protected:
string name;
public:
(List of functions)
}
But if I do that, my code just dont work when I write and read a binary file, but if I change the string to char array, for example:
class whatever{
protected:
char name[20];
public:
(List of functions)
}
It works good, so I wanted to know if there's some way to store a class wiht strings in binary files, or what am I doing wrong?
View 4 Replies
View Related
Feb 19, 2013
I know my product.cpp constructor is wrong but how can I set my private variables.
//PRODUCT.h
#ifndef PROJECT1_PRODUCT_H
#define PROJECT1_PRODUCT_H
[Code].....
View 2 Replies
View Related
May 4, 2014
I tried to implement a string class and i want to modify a specific char in my string . I did operator over load but this code crash in this line
name [2] = 'k' ;
Why ?!!!!!!!!!!!!!
this is my code
# include <iostream>
using namespace std;
#include <assert.h>
class String {
public :
char *content ;
int size ;
[Code] ....
View 11 Replies
View Related
Sep 30, 2014
I want this program by using only iostream.h & conio.h
View 4 Replies
View Related
Apr 19, 2014
I created class called students which suppose to store students names of in array but when I call the display function it display only the first name. but I want it to display names depending on the array size.
#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
[Code]....
View 3 Replies
View Related
Jul 3, 2014
There are two ways to access the members of class A inside class B:
1) Making an instance of class A in class B
2) Deriving class B from class A
So what is the basic difference in both ways as we can do same kind of work with both ways?
View 1 Replies
View Related
Jan 21, 2013
The case is like
class B{
public:
somedata;
somefunction();
}
class A{
public:
data;
function();
}
in somefunction i want a pointer to current object of class A m new to c++
View 2 Replies
View Related
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
Jan 21, 2014
The compiler creates virtual table for the base class and also for the derived class whether we override it or not.
That means each class has separate virtual table. when we get the size of the each class with out any data members... the size of base is -- 4 bytes(64 bit) and the size of derived is -- 1
The size of base class 4 is correct since it creates the virtual pointer internally and its size is member data + virtual pointer, but it in this case I have included any data members so it has given 4 byts.
But why in case of derived is 1 byte, since it the derived class has overridden the virtual function from base, this will also contains the virtual pointer which will be pointing to derived class Vtable, it the size of the class suppose to be 4 instead of 1 byte.
#include<iostream>
class A{
public:
[Code].....
View 1 Replies
View Related
Apr 26, 2014
I have my main.cpp like this:
#include <iostream>
#include "curve1.h"
#include "curve2.h"
using namespace std;
int main() {
Curve1 curve1Obj;
Curve2 curve2Obj;
[Code]...
Base class Score has two derived classes Curve1 and Curve2. There are two curve() functions, one is in Curve1 and other in Curve2 classes. getSize() returns the value of iSize.
My base class header score.h looks like this:
#ifndef SCORE_H
#define SCORE_H
class Score {
private:
int *ipScore;
float fAverage;
int iSize;
[Code]...
You can see that I have used curve1Obj to enter scores, calculate average and output. So if I call getSize() function with cuve1Obj, it gives the right size that I took from user in enterScores() function. Also the result is same if I call getSize() in score.cpp definition file in any of the functions (obviously).
.....
The problem is when I call curve() function of Curve2 class in main (line 23) with the object curve2Obj, it creates a new set of ipScore, fAverage and iSize (i think?) with garbage values. So when I call getSize() in curve() definition in curve2.cpp, it outputs the garbage. .....
How can I cause it to return the old values that are set in curve1.cpp?
Here is my curve2.cpp
#include <iostream>
#include "curve2.h"
using namespace std;
void Curve2::curve() {
cout << "getSize() returns: " << getSize() << endl; // out comes the garbage
}
Can I use a function to simply put values from old to new variables? If yes then how?
View 3 Replies
View Related
Oct 7, 2014
How to initialize a static member of a class with template, which type is related to a nested class?
This code works (without nested class):
#include<iostream>
using namespace std;
struct B{
B(){cout<<"here"<<endl;}
};
template<typename Z>
[Code] ,....
View 1 Replies
View Related
Dec 10, 2012
Linker error.
First off the error
Code:
Error1error LNK2019: unresolved external symbol "public: __thiscall ReachTop<class Character>::ReachTop<class Character>(class Character *)" (??0?$ReachTop@VCharacter@@@@QAE@PAVCharacter@@@Z) referenced in function "void __cdecl `dynamic initializer for 'gReachTop''(void)" (??__EgReachTop@@YAXXZ)Main.objDecisionTest
Reach Top class inherits from Goal Class
Goal Class
Code:
#ifndef _GOAL_H
#define _GOAL_H
#include "Action.h"
#include <list>
template <class T>
class Goal
[Code] ....
Code to create
Code:
Character* gCharacter = new Character(1, gWorld);
Goal<Character>* gReachTop = new ReachTop<Character>(gCharacter);
I can provide the character class and its inheritance aswell if you like.
View 4 Replies
View Related