Visual C++ :: How To Clone Object

Jul 24, 2014

I define two classes in C++, as follows:

class CBaseClass {
...
}
class CDerivedClass : public CBaseClass {
...
}

And want to implement a clone function as follows:

CBaseClass *Clone(const CBaseClass *pObject) {
}

When an object of CDerivedClass is passed to Clone, then the function will also create a CDerivedClass object and return.

When an object of CBaseClass is passed to Clone, then the function will also create a CBaseClass object and return.

How to implement such a feature?

View 3 Replies


ADVERTISEMENT

Visual C++ :: How To Search For Object That Has Been Hashed

May 27, 2013

Ran into a logic issue with my hashing program that stores a state object. It's storing the object just fine now but I need to be able to search for it. The user enters a state name and I'm supposed to be able to search for it. I am at a complete loss on how to handle hashing objects.

here is the main

Code:
#include <iostream>
#include <fstream>
#include <string>
#include "hashT.h"

[Code]....

View 2 Replies View Related

Visual C++ :: How To Reduce Size Of Object

Feb 10, 2014

I am using Visual C++ to write an app. I write CMyObject class and may allocate a lot of instances of CMyObject object, so I want to reduce the size of CMyObject class.

What I can figure out to do is:

1. I can use the following code to get the accurate size used by a single instance of CMyObject object:

CMyObject Object;

//Get the size of memory allocated for CMyObject object
int nSize = sizeof(Object);

is that correct?

2.To reduce the size of CMyObject, I have several ideas:

(1)Change member function to static member function if it is possible, since each member function will take some spaces in the instance of CMyObject.

(2)Change virtual member function to member function if it is possible, since virtual member function may take more spaces.

(3)Eliminate unnecessary member variables to reduce spaces.

(4)Finally, if (1), (2) and (3) does not work well, then change CMyObject from class to a struct that only contains some member variables, thus will eliminate the spaces allocated for constructor and destructor of a class.

View 2 Replies View Related

Visual C++ :: Compiler Error With Cout Object

Dec 15, 2012

I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure.

Code:
srand(static_cast<unsigned int>(time(0)));
int choice = rand() % NUM_WORDS;
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];

[Code] ....

The error is happening on the last output operator, just before the jumble variable on the last line.The error is:

Code:
Intellisense: no operator"<<" matches these operands

operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string

I understand what its saying, but jumble is a std::string

Here are my preprocessor directives and using statements

Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

View 4 Replies View Related

Visual C++ :: Object As Data Member Having Error

Sep 20, 2012

class CPop {
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;
}

error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'

I don't know y these errors, it runs fine in simple c++ environment

View 14 Replies View Related

Visual C++ :: Include Object From Another ATL COM DLL - Employee Classes?

Nov 7, 2014

This refers to an ATL COM DLL project. I can successfully create a class hierarchy of objects, ie. say, one class is the TEAM, which then holds other objects, say, a leader and a secretary, both of which are Employee Classes . Here goes my question:

a) In the Team.h header file I declare m_pLeader as a CComPtr<IEmployee>

Code:
classATL_NO_VTABLE CTeam :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CTeam, &CLSID_Team>,
public IDispatchImpl<ITeam, &IID_ITeam, &LIBID_BUOBJ05Lib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
private:
CComPtr<IEmployee> m_pLeader;
CComPtr<IEmployee> m_pSecretary;

b) The Employee Class is defined within this ATL COM project.
c) In the Team.cpp file, I create an instance in the FinalConstruct code, the focus is on the CEmployee

Code:
HRESULT CTeam::FinalConstruct(){
CComObject<CEmployee>* pLeader;
HRESULT hr=CComObject<CEmployee>::CreateInstance(&pLeader);
if (FAILED(hr))
return hr;
m_pLeader=pLeader;
// ..same for secretary...
return S_OK
}

d) Here comes my QUESTION: How must I proceed if the Employee object was part of another ATL COM DLL, that is it would be described in another DLL that I would now like to reuse? I guess I need to

1. Have the other DLL's idl-, tlb, and h file in my project folder. Let me name it "other.h, other.idl, other.tlb"

2. Both h- and cpp-file must have an #include "other.h" statement -- please correct if I am wrong..

3. ...but how must in the Team's h- and cpp-files the statements be (assuming the class in the "other" Dll is Member (instead of Employee? I know the following code will NOT work, so I am asking how it should be correctly?

Code:
private:
CComPtr<IMember> m_pLeader;

4. and in cpp file for:

Code:
CComObject<CMember>* pLeader;
HRESULT hr=CComObject<CMember>::CreateInstance(&pLeader);
[/code]

View 10 Replies View Related

Visual C++ :: MF Dialog App - Deleting HBITMAP Object

Mar 6, 2015

I have a little demo of a bitmap button that simply uses CButton and resource bitmaps in an MFC dialog app. The intent is to click on the button and have the bitmap image change. My code works ok the first time around, but crashes on repeat clicks. I have interpreted this as failure to properly delete the HBITMAP object, though I could be mistaken. In any case the app works ok in Release configuration but violates assertion in Debug.

Code:

ASSERT(m_hObject == NULL); // only attach once, detach on destroy[code]
// dialog header
// Attributes
protected:
HBITMAP m_hBitmap1;
HBITMAP m_hBitmap2;

[Code] .....

View 9 Replies View Related

C++ :: Will Copy Constructor Does Object Initialization Using Another Already Created Object

Mar 16, 2013

will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?

View 10 Replies View Related

C# :: Method Is Overwriting Both Instance Of Object And Original Object

Jul 3, 2014

I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.

public static int recurse(int count, Tile[,] b,Huristic h,int check) {
if (check==1) {
boardState.Add(B)/>;
return check;
} if (check == 0)

[Code] .....

View 6 Replies View Related

C++ :: Importance Of Static Object In A Class And How They Are Different From General Object

Dec 13, 2012

#include "B.h"
class A {
public :
A()
{
s_b = new B();
b = new B();

[Code] ....

In my project i have seen static object as above . But not able to know what is the exact use of it and how they are different from general object .

View 2 Replies View Related

C++ :: What Can't Non-const Object Receive Temporary Object

Sep 11, 2014

a function returns a temporary object like

int myfun(){
int x = 0;
return x;
}

this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???

View 7 Replies View Related

C# :: Constructor Object Reference Not To Set Instance Of Object

Mar 28, 2014

I am trying to use web api in order to return custom json response keys. For this i have return a custom class to return json response

Custom Class:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

[Code].....

View 2 Replies View Related

C Sharp :: Object Reference Not Set To Instance Of Object?

May 4, 2013

I have a combobox with Items 1024
2048
4096
8192

String cach = form.comboCache.SelectedItem.ToString();

I am using the above code to retrive an item selected by user,But this line is giving an exception "Null Reference Exception, Object reference not set to an instance of an object"

View 1 Replies View Related

C# :: Object Reference Not Set To Instance Of Object?

Mar 28, 2014

I am using session to pass object from controller to custom class in MVC Web API. here is my code, i am getting error at session.

public HttpResponseMessage Get()
{
var person = db.Persons.ToList();

[Code]....

View 1 Replies View Related

C/C++ :: Get Reference To Text Object With The Name Of Object?

Aug 23, 2013

In Visual Studio 2010 C++
I have a series of existing text objects
The text properties names are
item1_lbl,
item2_lbl,
item3_lbl,
….

Based on a selection I want to change an object. I generate the name of the object I want to change in a string so from this string is there a way to get a pointer to the correct text object that is same name?

View 3 Replies View Related

C++ :: Starting Vertex Array Object At Index Of Vertex Buffer Object

Sep 22, 2014

I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.

Type definitions:

struct vertex_t {
vector3d_t position;
float s; // Texture coordinate s
float t; // Texture coordinate t
};

Code so far:

// How do I make this start at a certain spot of the VBO?!
glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr;
//...

View 1 Replies View Related

C++ :: How To Get Object Of Original Class From Function Of Other Class Where Other Class Object Is Member Of Original Class

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

C :: How To Create An Object

Oct 31, 2013

I have an assignment that asks me to implement a variant of the classic bouncing balls program.

'Each ball should start off at the top of the screen with a random speed in the x direction. Whenever a ball hits a screen boundary it should bounce off at an angle equal to the impact angle and lose some speed. Eventually each ball should come to a rest at the bottom of the screen. Five seconds after coming to a rest a ball should be removed from the screen.'

'Your code must keep track of objects (balls) by placing the object data structures in a linked list. You need to create your own linked list implementation. Below is a brief description of the object programming interface: CreateObject - Create a new object. The function accepts as input parameters a pointer to the SDL screen, a pointer to a model triangle array, and a variable telling the size of the model triangle array. The function returns a pointer to a new object data structure. The model triangle array specified as input parameter should not be shared across objects. (Not sharing the model triangle array allows e.g. objects to have different colors.)

Perform the necessary memory allocation and copying.DestroyObject - Free object. The function accepts as input parameters a pointer to an object data structure. The function should free all memory allocated to represent the object (memory allocated for the model triangle array and the object data structure itself).

Drawobject - Draw object on screen. The function accepts as input parameters a pointer to an object data structure. The function must draw the object on the screen by calling DrawTriangle on each of the model triangles. Remember to update scale, translation, etc., in each triangle data structure before invoking DrawTriangle.

Hint: Do not make the bouncing algorithm too complex. Bouncing a ball off a vertical or horizontal surface can be accomplished without resorting to calculating impact angles.'

The function I'm stuck at, is the first one - createobject.

My first aim is to get one ball on the screen.

Code:

// Create new object
object_t *CreateObject(SDL_Surface *screen, triangle_t *model, int numtriangles)
{
object_t *object = malloc(sizeof(object_t));
object->model = malloc(sizeof(sphere_model));
object->screen = SDL_Surface;
memcpy(*model, object->model, sizeof(object_t));
return object;
// Implement me
}

This is what I've done so far.

View 4 Replies View Related

C++ :: How To Use Object From Another Class

Dec 21, 2013

I have two classes one called Date and the other is University , Date class has two overloaded operators , ostream and istream to take in the data and print them out :

ostream & operator<<(ostream & out, Date & x) {
out<< x.month << "/" << x.day << "/" << x.year ;
return out;

[Code] ....

The University class has an object of type Date called establishDate and I must use this to print out the date along with the University name and location, here's University class :

University.h

class University {
public:
University (); // constructor
friend ostream & operator<<(ostream & out, University & x); // print the university data
friend istream & operator>>(istream & in, University & x); // to read university data

[Code] .....

so how do I use the establishDate object ?

View 2 Replies View Related

C++ :: Getting A Type From Object

Apr 20, 2013

it is not possible to get a type from an object, only from a type. Even with auto, you can only instantiate another type of the same type.I'd like to get a type from an object given another type, mainly because it is less typing and less error prone.

Some psudocode:

Type1 A<X, Y> a;
int b;
Type2 a.InnerType<b>::type c; // obviously won't work

A work around I thought of would be to use functions:

Type1 A<X, Y> a;
int b;
auto c = a.getInnerType(b);

Which is kinda interesting and looks like the way I'm going to go. However, I'm just wondering if there is any other ways of doing this as I don't really want to instantiate an object if I can avoid it (though the optimizer will probably just dump it anyway).

View 2 Replies View Related

C++ :: How To Link An Object To Another One

Jun 27, 2013

I have the following problem, I have an object of a class Subject, and I want that this object points to another object of class Classes, creating a kind of link. How can I do that?

View 4 Replies View Related

C++ :: Object Variables Going To NaN

May 26, 2014

So I am trying to develop a sort of 2d spacesim engine for creating games in C++. The project uses SFML for graphics, and I am currently trying to compile it on Linux using g++.

The main issue that I am wrestling with is that of simulation objects having their position, velocity, and rotation variables constantly getting set to NaN for reasons that are beyond me. The behaviour is not consistent, and occasionally will occur or not occur without any discernible pattern.

The github repo for the code is here: [URL] ....

I understand that NaN values can spread easily by operations on one another, but I cant seem to figure out where the initial issue is occurring here.

View 2 Replies View Related

C++ :: How To Get Object Name In The Constructor

Mar 11, 2013

is it possible to get object name in the constructor? I would like to initialize an object of circle class without any arguments and put some pretty lines in constructor to get and save as table of chars the name of creating object. Is it possible? I work with MSVS2012.

View 4 Replies View Related

C++ :: Cannot Delete Object

Apr 18, 2014

int NextPixel(int antIndex, int currentPixel , Ant *ant , IplImage *edgeImg) {
int left = currentPixel - 1 ;
int right = currentPixel + 1 ;
int up = currentPixel - edgeImg->widthStep ;
int down = currentPixel + edgeImg->widthStep ;

[[Code] ....

if those lines are uncommented , program gives heap error.Why?

View 3 Replies View Related

C/C++ :: Why And Where To Use Nameless Object

Mar 24, 2013

why we use this object and what purpose we use it

View 2 Replies View Related

C++ :: How To Return Another Object Value

Nov 8, 2014

How can I return other object's value in a function(see code and comments)?

Person.h

Code:
#include <iostream>
#include <string>
using namespace std;
class Person{
public:
Person();
Person(string pname, int page);

[Code] ....

View 14 Replies View Related







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