Visual C++ :: Pointer / Reference To Class Within Class?

Oct 3, 2012

I have encountered a problem I can't see to solve. I want to access a function and can't seem to find the right combination to get me there. Here is what I am looking at:

CFoo1::CFoo2::GetStrDataC(int nRow) const

How do I call the GetStrDataC function from another class?

View 6 Replies


ADVERTISEMENT

Visual C++ :: How To Get Pointer To CMyView Class From CMainFrame Class

Nov 29, 2013

My program is a basic MFC AppWizard (exe) created project in VC++ 6. In MainFrm.cpp, I am trying to access some user defined CMyView member functions. However when I try to do the standard procedure to get the CMyView pointer in MainFrm.cpp, I get the " ... 'CMyView' : undeclared identifier" error. To resolve this, I add " #include myView.h " at the top of MainFrm.h which then produces the following errors:

Code:
myview.h(21) : error C2143: syntax error : missing ';' before '*'
myview.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers
myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers

What do these errors mean? Is there a simple way to access CMyView member functions from CMainFrame?

View 8 Replies View Related

C++ :: Cast Base Class Pointer To Derived Class Pointer

Feb 6, 2015

I create an instance of a base class (not derived class) and assign it to base class pointer. Then, I convert it to a pointer to a derived class and call methods on it.

why does it work, if there is a virtual table?

when will it fail?

// TestCastWin.cpp : Defines the entry point for the console application.//

#include "stdafx.h"
#include <iostream>
class B
{
public:
B(double x, double y) : x_(x), y_(y) {}
double x() const { return x_; }

[Code] ....

View 14 Replies View Related

C++ :: Deleting Array Of Derived Class Objects Through Base Class Pointer

Mar 21, 2015

In this book, item 3 is about never treat arrays polymorphically. In the latter part of this item, the author talks about the result of deleting an array of derived class objects through a base class pointer is undefined. What does it mean? I have an example here,

Code:
class B
{
public:
B():_y(1){}
virtual ~B() {
cout<<"~B()"<<endl;

[Code] ....

This sample code does exactly what I want. So does the author mean the way I did is undefined?

View 1 Replies View Related

Visual C++ :: Passing Class Pointer Via Socket

Oct 14, 2013

I have a function called,

App 1:
void GetImage(CImage * img) {
//Pass &img over socket to another app
}

App 2:
void DisplayImage() {
CImage * pImg = &img;
}

Is it possible to pass a class pointer as memory buffer across the socket? The above code is just an example. My question in general is, whether it's possible to pass any Classes pointer as a memory buffer across sockets.

View 7 Replies View Related

Visual C++ :: How To Get Pointer To CDialogBar From CView Class

Nov 22, 2013

My program (Test) is a basic MFC AppWizard (exe) created project. I have followed the steps in the link below to create a docked dialog box (myDialog) using VC++. [URL]...

The dialog box works, however, I have 2 issues that I am trying to resolve.

1) I have added a button to the Dialog box, however, when I run the application they start as disabled (note: the Disabled option on the Button Properties is unchecked). If I add function myDialog::OnButton to the myDialog class, the button remains disabled, however, if I add the function CTestView::OnButton to the View class, the button becomes active and works. How can I make the button work from the myDialog class?

2) I would like to be able to change an Edit box in the same dialog box when I click the button. How can I access the pointer to the myDialog from the View class?

View 2 Replies View Related

Visual C++ :: Friend Class And Pointer Function

Mar 9, 2013

I need understanding this block of code, particularly this line : *getLeftChild() { return this - _child; }

Code:

public class UpperNode {
BOX _box;
int _child;
FORCEINLINE UpperNode *getLeftChild() { return this - _child; }
...
};

Here I have this function:

Code:
void
UpperNode::visulization(int level) {
if (isLeaf())
_box.visulization();
else
if ((level > 0)) {

[Code] .....

It also makes calls for "getLeftChild()";

But I see that getLeftChild expects function pointer, and I absolutely have no clue where "this" comes from inside function body.

(return this - _child) - "this" has to be integer.

Or, if we gave pointer, and "this" is referring to some UpperNode, then I can't understand to which one, I have no UpperNode array defined or something. So if this functions is actually scaling pointer address, then scaling where to? I could comprehend it, if I had some array of UpperNodes, but not just class. I have UpperNodes array defined in other friendly class, but don't think they are related .....

View 2 Replies View Related

Visual C++ :: Pointer To Incomplete Class Is Not Allowed

Jun 16, 2013

Here is the pseudocode,

Code:
class myDX9Widget {
std::vector<Object*> m_vRenderObjects;
};
class Object {
};
class Lorry : public Object {
Activity *activity;

[Code] .....

Don't worry about the exact syntax here, I'd like to concentrate, on a conceptual level, why the line

lorry->Owner->m_vRenderObjects.push_back(pallet);

is not allowed

lorry is regarded as "Pointer to incomplete class"

View 4 Replies View Related

C++ :: Pimpl Class With Pointer To Base Class?

Jun 28, 2012

I'm trying to implement a class hierarchy and a wrapper class with a pointer to the base class. The base class has operator< overloaded and the implementation makes use of virtual functions as some of the logic for sorting is in the derived classes. Unfortunately, when trying to use the base class operator< from the wrapper, I get a "pure virtual method called".

Below code is meant to illustrate my problem. Unfortunately it crashes on me (upon destruction of vec) and I cannot quite see, why. So two questions:

1. spot the error I made in the code below (having lived in Java-land for the last 5 years, I'm sure I just did some stupid error)?

2. How can I implement Wrapper::operator< to use Base::operator<? I know I could write a function and pass it to sort but I'm interessted if there is a way to actually use Base::operator<.

Code:
#include <vector>
#include <algorithm>
#include <cmath>

[Code].....

View 3 Replies View Related

Visual C++ :: Reach Top Class Inherits From Goal Class - Linker Error

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

Visual C++ :: Syntax In Class Definition While Inheriting Another Class

Apr 21, 2014

#include "IMyIntData.h"
class MyIntData : public CPMUnknown<IMyIntData>
{

I need to know what this syntax means (including MyIntData in angular brackets after parent class name) where IMyIntData is the Interface from where MyIntData is derived.

View 1 Replies View Related

Visual C++ :: Access Variable Inside Class From Other Class

Nov 9, 2013

I am trying to access a variable from another class through another class but it is not returning its "instance"?

Example:
Class View

Code:
...
V3D_Viewer viewer;
...
Class MainWindow

Code:
...
viewer* myView;
myView = new viewer();
...
Class Test

Code:
...
MainWindow window;
window.myView->setBackgroundColor(WHITE);
...

I am new to c++ references and pointers,

View 3 Replies View Related

C++ :: Calling Defined Function Pointer From Another Pointer To Class Object?

Aug 19, 2014

I am attempting to implement function pointers and I am having a bit of a problem.

See the code example below; what I want to be able to do is call a function pointer from another pointer.

I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.

class MainObject;
class SecondaryObject;
class SecondaryObject {
public:

[Code]....

View 10 Replies View Related

C++ :: Pass Class Object By Reference

Jun 25, 2013

I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.

bool COAuthSDK::GetRequestToken(CClientDetails &objClientDetails)

it has this info of what it needs :

Name IN/OUT Description
m_environment IN Optional. Possible values are SANDBOX (default) and LIVE.
m_strConsumerKey IN OAuth consumer key provided by E*TRADE
m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE
m_strToken OUT Returned by the function if successful
m_strTokenSecret OUT Returned by the function if successful
m_strCallback IN Optional; default value is "oob"

here is the COAuthSDK header

#ifndef _OAUTHSDK_H_INCLUDED_
#define _OAUTHSDK_H_INCLUDED_
#include "ETCOMMONCommonDefs.h"
#include "ETCOMMONOAuthHelper.h"
using namespace std;

[code].....

when I try to build the function it says that its in the dll's so I know I have to call it.here is the link to the build site if needed URL....

View 1 Replies View Related

C++ :: Undefined Reference To Class Definition

Aug 4, 2013

I have successfully built OGDF under directory undefined reference to /home/vijay13/Downloads/OGDF-snapshot/

I have following code in test.cpp under directory /home/vijay13/Downloads/ :

#include <ogdf/basic/Graph.h>
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;

[Code] .....

while compiling as following :

vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/

I am getting following error:

vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/
/tmp/ccPE8nCu.o: In function `main':
test.cpp:(.text+0x26): undefined reference to `ogdf::Graph::Graph()' ...................... so on

View 2 Replies View Related

C++ :: Pass Class Object By Reference?

Mar 17, 2014

I'm trying to pass a class object by reference.

total = mathfunction(i);
}
double mathfunction(retirement& j)
{
double R = 0.00, m = 0.00, r = 0.00, t = 0.00, totaled = 0.00,
numerator = 0.00, denom = 0.00, temp = 0.00;

[Code]....

I only tried to pass by reference because I figured passing by value would be a larger pain in the neck.

View 1 Replies View Related

C++ :: Assignment Operator For A Class With Reference

Mar 6, 2014

Class A
{..........}

Class B:
{....
private U& u;}

I need to write the copy constructor and assignment operator for Class B above. Copy would look something like this:

B::B(conts B& bo): u(bo.u){}

is this correct ... and how will the assignment operation look like??

View 3 Replies View Related

C++ :: Reference Semantic For Pimpl Class?

Jun 18, 2012

I have a basic class with a pimpl, with agressive instantiation:

Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : pImpl(new MyClassImpl) {}

[Code] ....

Classic/Standard. However, I do hate having to use pointer semantics for all of my operations. So I thought: If I never ever manipulate the actual pointer itself, why not just keep a reference?

Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : impl(*new MyClassImpl) {}
~MyClass(){delete &impl;}
private:
MyClassImpl& impl;
};

The only downside that I see, is that I can't swap or move, but this particular object is not meant to be swapped or moved.

View 4 Replies View Related

C++ :: Inherited Class Constructor - Undefined Reference

Jun 18, 2013

I have three classes 1 base and two inherited.. problem is when I try to initialize the it says undefined reference to vtable constructor.

Code:
#ifndef QUOTE_H_INCLUDED
#define QUOTE_H_INCLUDED
#include <string>
using namespace std;

[Code] ....

View 2 Replies View Related

C++ :: Explicit Conversion From String To Class Reference?

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

C/C++ :: Catching Base Class Exception As Reference

Jul 23, 2013

class BaseExcep {
protected:
      std::string message;  
public:
      BaseExcep(std::string);
      virtual void printException();

[Code] .....

Here i need to find which exception type is actually thrown.

Whether it is DerivedExcep1 or DerivedExcep2 or  BaseExcep itself.

I can't use dynamic_cast in this, since it is a reference ....

View 5 Replies View Related

C/C++ :: When To Use Class And When To Use Pointer To A Class

Apr 29, 2015

I want to ask about pointers to classes vs just classes. I have used classes such as QTimer with and without pointers, and I don't know when to use pointers. Sometimes you can't because a function returns a class, not a pointer to a class. But usually you can do either.

When should you use a pointer?

View 4 Replies View Related

C++ :: Tile Based RPG - Undefined Reference To Class Function

Mar 13, 2014

I'm making a simple tile-based RPG and I've run into a bit of trouble when I put my code into classes.

Heres my main

#include <iostream>
#include "windows.h"
#include "math.h"
#include "time.h"
#include <string>
#include "Goblin.h"
#include "User.h"
#include "Inventory.h"
#include "Maps.h"
using namespace std;
void treasureGet();

[Code] ....

My other 3 classes have the same structure and the same error for all their functions.

This is the exact Error

undefined reference to `Goblin::goblinBattle()'|
undefined reference to `Goblin::goblinBattle()'|
undefined reference to `Goblin::goblinBattle()'|
undefined reference to `Goblin::goblinBattle()'|
undefined reference to `Inventory::inventoryOpen()'|
undefined reference to `Goblin::Goblin()'|
undefined reference to `User::User()'|
undefined reference to `Inventory::Inventory()'|
undefined reference to `Maps::Maps()'|
||=== Build finished: 9 errors, 29 warnings (0 minutes, 0 seconds) ===|

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++ :: Creating New Pointer For A Class

Aug 2, 2013

I'm currently reading the C++ Guide for Dummies

Anyway right now I'm working with pointers and classes, and when I create a new pointer for my class it looks like this...

Pen *Pointerpen = new Pen;

But in the book they threw in this...

Pen *Pointerpen = new Pen();

Can you actually designate memory space for a function? Or was this a typo on their part? It's never come up before and they didn't explain it.

View 5 Replies View Related

C++ :: A Pointer To Base Class

May 18, 2013

A pointer to base class, if assigned to a derived class, only points to the base part right? So you can only use the base part of the derived class with that pointer and no methods from the derived class?

View 8 Replies View Related







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