C++ :: Compiler Will Not Allow To Call A Public Method In Another Class

Feb 23, 2013

I have read the book over and over and I thought I understand "CLASS". But when I applied it and write the code the compiler tells me that there is a compiling error.

1. I have this method addProduct(Product* pProduct) in a Class called ProductRack, the code is in ProductRack.cpp file. The declaration of the Class methods and private variables are in ProductRack.h header file.

2. But when I call a method in the DeliveryCHute Class from the ProductRack Class I get a compiler errors which are these:

A.IntelliSense: a nonstatic member reference must be relative to a specific object
B.error C2352: 'Project1::DeliveryChute::insertProduct' : illegal call of non-static member function

And this is causing the error:

if (Project1::DeliveryChute::insertProduct(pProduct) == false)

//THIS IS JUST ONE METHOD INSIDE ProductRack.cpp
bool
Project1::ProductRack::addProduct(Product* pProduct) {
// Todo : Implementing
if (Project1::DeliveryChute::insertProduct(pProduct) == false)
return true;

[Code] .....

View 5 Replies


ADVERTISEMENT

C++ :: How To Call Class Method / Function From HXX File In CPP File

Feb 11, 2014

How do I call a class method which is defined in a .hxx file separately to a .cpp file? Is it any different from how we normally do it (using the scope resolution operator after the class name and then the method name with parameters) ?

View 1 Replies View Related

C++ :: Pass Method Of Derived Class As Parameter To Another Method In Base Class?

Feb 2, 2015

I have a question similar to the one here: [URL] .....

The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.

template <typename BaseType>
class Base {
public:
typedef void (Base::*Callback)(int A);

[Code] .....

The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.

Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.

View 2 Replies View Related

C++ :: Public And Private Functions With No Class?

Jul 7, 2012

I've been writing my own implementation of quicksort in a .h file. I've gotten to the point where I think I'm done with the algorithm, so now I'm trying to make it so that if someone includes "quicksort.h", they will only have access to certain functions in the file. Kind of like public and private functions in a class, but without the "class" part of it. How do you do that?

View 7 Replies View Related

C# :: Unable To Use Public Class And Private Subs With Combo Boxes?

May 18, 2014

I've finally managed to do something with the combo box but knock down one wall it's like there's another one five inches behind it. What I mean is I've figured out how to add items to the combo box and have them show images in my picture box. Only problem is when I went to debug my combo box kept looping it's options over and over and over.

Private Sub
xpmaleskincolorselect.Items.Add("Tone1"); malesprite.Image = My.Resources.Resources.XP_Female_clear;
xpmaleskincolorselect.Items.Add("Tone2"); malesprite.Image = My.Resources.Resources.XP_Male_tan;
xpmaleskincolorselect.Items.Add("Tone3"); malesprite.Image = My.Resources.Resources.XP_Male_dark;
End Sub

The subs, I know they aren't right but its just to show I know where they go. Anyway using Private Sub and End sub doesn't seem to work. I'll type them in then at the error box at the bottom it'll say that it doesn't exist in the namespace. Same thing happened when I tried to add public class beforehand to see if that would work same thing about the name space.

View 8 Replies View Related

C++ :: Creating Public And Static Field In A Class - Unresolved External Symbol Error

Apr 5, 2014

I'm trying to create a public and static field in a class called ResourceManager. But when trying to access the field even from inside the class it wont work. I'm getting this error message:

Error 1 error LNK2001: unresolved external symbol "public: static int ResourceManager::num" (?num@ResourceManager@@2HA)

Here's my code:
ResourceManager.h

Code:

class ResourceManager {
public:
static int num;
static void loadContent();

[Code] .....

I'm using Visual Studio 2012.

View 2 Replies View Related

C++ :: No Matching Function For Call To Method?

Dec 11, 2014

I need to call one function on my C++ program. I made one root calculator for functions, but, this doesn't work.

// FUNCION QUE CALCULA LA DIFERENCIA ENTRE 2 VECTORES
real mn_error_vectores(Array1D< real > &u, Array1D< real > &v) {
int i;
if(u.dim()!=v.dim()){
printf("mn_error_vectores() : arrays of different dimensions

[Code] ....

View 4 Replies View Related

C++ :: Variable Belonging To Base Class - Tell Compiler Consider This To Be Derived Class?

Oct 12, 2013

I have an example where I have a variable belonging to a base class, but I would like to tell the compiler that it actually belongs to a derived class. How can I do this?

// base class: R0
// derived class: R1
// see function SetR1 for the problem
class R0 {
public:
int a;

[Code] .....

View 5 Replies View Related

C++ :: Friendship From Derived Class Method To Base Class Members

Jul 15, 2014

I would like to know if there's a way to make a method from a derived class a friend of its base class. Something like:

class Derived;
class Base {
int i, j;
friend void Derived::f();
protected:
Base();

[Code] ......

View 3 Replies View Related

C++ :: Class Not Seen By Compiler?

Sep 18, 2014

I have an issue. VS 2013 isn't recognizing objects that I've declared when I use class functions.I'm getting this error: "Line 14 and 15: Error C2228: left of '.asciiToFpc6' must have class/struct/union"...Here's the relevant code:

Source.cpp

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "fpc6.h"

[code].....

Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....

View 9 Replies View Related

C++ :: Can Base Class Call Overridden Function From Derived Class?

Aug 28, 2013

I just wondering if a base class can call the overridden function from a Derived class?

Here's an example:

//Base Class H
class BaseClass {
public:
BaseClass();
virtual ~BaseClass();
virtual void functionA();

[Code] ....

So basically, when I am creating a new object of Derived class, it will initialize BaseClass and the BaseClass will call functionA but I want it to call the function overridden by Derived class.

I know that if I call newObj->functionA it will call the overridden function. Right now I want the base class to call the overridden function "this->functionA(); in BaseClass" during its initialization. Is it possible to do that?

View 9 Replies View Related

C++ :: Simple Class Usage Compiler Error

May 12, 2013

Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)

I created a class called Point, in Point.h

I created a class called Rectangle in Rectangle.h and Rectangle.cpp

If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.

Question:

I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.

Code:
$ g++ main.cpp -o main
/tmp/cc38JIph.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)'
main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const'
collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?

And the files, of course:

file: main.cpp
Code:
#include <iostream>
#include "Rectangle.h"
using std::cout;
using std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Shape Class Polymorphism Compiler Error

Dec 10, 2014

Having issues with program to create a shape area calculator with circle square and rectangle. the uml goes as follows:

Where the UML has shape as the abstract class with public area():double, getName():string,and getDimensions:string, rectangle derived from shape with protected height, and width, and a public rectangle(h:double, w:double), followed by a derived square from rectangle with just a public square(h:double), and finally a circle derived from shape with a private radius, and a public circle(r:double).

[URL]

Have linked my program and it is giving me the following compiler errors:

error: 'qdebug' was not declared in this scope line 15 of main

error: cannot declare variable 'shp' to be of abstract type 'shape' line 22 of main

error: expected primary-expression before ')' token lines 29 -31 of main

(note previously had qstring as a header file yet changed to string since I was getting error qstring was not declared in this scope.)

View 5 Replies View Related

C++ :: How To Call Function From Derived Class In Base Class

Dec 24, 2013

Basically, I have a base class called MainShop and it has 3 derived classes which are SwordShop, SpellBookShop and BowShop. I want the base class to be able to call a function from one of the derived classes but no matter what i do, it doesn't seem to work!

Here is my code:

#include "MainShop.h"
//BaseClass cpp
void MainShop::EnterShop(Hero& hero)

[Code]....

I have two other derived classes, but its basically the same concept. I have a function in one of the derived classes and i would like to call it from the base class. This is one my derived classes:

//SwordShop derived cpp
#include "SwordShop.h"
void SwordShop::soldierShop(Hero& hero)
{
/* some code here*/
}

View 4 Replies View Related

C++ :: Compiler And Linker Errors For Linked List Class And Application

Aug 31, 2014

I am trying to write a program that will take a list of integers from a file and write them to another text file. I've been banging my head at this for days trying to get it to compile as it is riddled with linker and compiler errors.

**************************header*************************

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class T>
class linkedList {

[Code] ....

View 6 Replies View Related

C++ :: Call From Class Created Inside A Class

May 21, 2014

I have 2 Classes.
-> StateManager
-> Intro

The StateManager creates the Intro. I want that the Intro calls a function of the StateManager if finished. How can I achieve that?

At line 24 at the Intro class you can see what I tried.

StateManager:

#pragma once

#include "State.h"
#include "Intro.h"
class StateManager{
private:
std::vector <State*> States;

[Code] .....

View 5 Replies View Related

C++ :: Access Another Library (DLL) Which Has Same Class Name And Method Name

May 27, 2013

I have 2 c++ libraries called "Lib1" and "Lib2". Both libraries have same class called "Total.h and Total.cpp"

I want to access lib1 class in lib2. since it has same class (i.e same header file), i couldn't refer lib1's members in lib2.

Lib 1 :

Total.h :
class Total {
public:
static void Test(double);

[Code] .....

How to access another library which has same name and how to add header file ?

View 1 Replies View Related

C# :: How To Access Form Method From Another Class

Jan 7, 2015

Basically am trying to reference a method in a my Form1 class into another class. So far I have tried multiple different methods to try and access the method but have not managed it so far. Both classes use the same namespace. The part of my form class that I am using are as follows:

public class Form1 : Form
{
IContainer components = null;
private ButtonPanelThread p1, p3, p4;

[Code]....

View 4 Replies View Related

C++ :: Can A Class Constructor Be Called Like A Method?

May 17, 2013

When the below is done, does it call the constroctor only, and if yes, constructors do not have return types so how does it work? is there anything behind the scene?

wxAddHandler(new wxPNG_HANDLER);
and
sf::RenderWindow(sf::VideoMode(...),...);

View 6 Replies View Related

C++ :: How To Create Template Method In A Class

Jul 8, 2014

Code:

class A {
public:
template<class T>
ObjectsBase* createObject(T* objType, Ogre::String name, Ogre::Vector3 position);
};
template<class T>
ObjectBase* A::createObject(T* objType, Ogre::String name, Ogre::Vector3 position);

My goal is to create any ObjectBase* derived object and return it to class A....

View 6 Replies View Related

C++ :: Invoking Method Of Class With Template

Aug 1, 2014

Code:
bool CObject<class T>::Create(LPDIRECT3DDEVICE9 pDevice, T *pMesh, float fAnimSpeed) {
if(pMesh == NULL)
return false;
m_pDevice = pDevice;
m_pMesh = pMesh;
if(m_pMesh->GetAnimController() != NULL) {
DWORD dwNumAnimSet = m_pMesh->GetAnimController()->GetMaxNumAnimationSets();

In here, T can be from the class CMesh * or CSkinnedMesh *, both have signature of GetAnimController

This maybe a flaw in my design... But I want Create to accept any kinds of meshes.

Should I create an interface or abstract class above all of those?

I have added an IMesh class that every derived classes has to have the needed interface.

But since then, I have another question, I feel that it is very cumbersome to include a template argument in every class/prototype that is associated with CObject

Say
bool CreatePlanesFromObject(CObject *pObject, D3DXPLANE *pPlanes);
Requires me to do this
template<class T> bool CreatePlanesFromObject(CObject<T>* pObject, D3DXPLANE* pPlanes);

Any ways I can omit the template argument, because it doesn't make sense to know the Mesh type in other classes...

View 1 Replies View Related

C++ :: Cannot Define Method Of Inner Nested Class If It Is Private

Jan 16, 2013

it seems that I cannot define a method of an inner nested class if it is a private class. for example:

class outter {
class nested {
void foo ( void ) {} // okay - but is this inline?
} void inner::foo( void ) {} // not okay - cannot define inside another class
} void outter::inner::foo( void ) {} // not okay - 'nested' class is private!

what I want to know is, is there another way to define an inner class's method? and if not, is it eternally doomed to be inline because it has to be declared inside it's own class declaration?

View 5 Replies View Related

C++ :: Calculate Bond Price Given A Certain YTM Using Class Method

Feb 22, 2015

I have been trying to calculate the bond price given a certain YTM using class method. Since the YTM and bond price are linked with each other(there is another question asking us to calculate the YTM with a given price),we put price and YTM in "private" and others variables in"public". Actually, this is the format given in my assignment.

I used "getvalue" to get the value of YTM, and used YTM in the formula of bond price calculation. However, the output of the price is infinite, while the output of price is right if I used a specific value of YTM(such as 0.05) in the formula. It means that I didn't successfully get right value of YTM.

#include <iostream>
#include <cmath>
using namespace std;
class bond{
public:
bond(){};

[Code] .....

View 1 Replies View Related

C++ :: Compile Method Of Class Separately From Other Methods?

Apr 11, 2014

There is any method to compile a method of a class separately from the other methods and the main.

View 1 Replies View Related

C# :: Invoke Method In Nested Class Using Reflection

Jun 25, 2014

I am having problems invoking methods in a nested class using reflection. I have the following:

A parent class, Group, that holds instances of a simple class called Signal. I want to modify the number of instances inside the group class often. So, all my code has to be dynamic and use reflection to know how many instances of signal there are inside the Group class.

class Group{
public static Signal name1 { get; set; }
public static Signal name2 { get; set; }
public static Signal name3 { get; set; }

[Code]....

I had no luck invoking the method of the instances of signal class that are inside the Group class. I tried getting the methods name using getMethods() but could not navigate through the syntax.

How could I invoke and pass parameters to the method of the instances of signal using reflection? Is there a better way of accessing the properties and methods of nested classes?

View 4 Replies View Related

C# :: Accessing Method Within Proxy Class But Fails To Do So

Jun 23, 2014

I have this proxy class generated from a webservice:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="java:se.atg.aisbean.calendar")]
public partial class RaceDayCalendarSimple : object, System.ComponentModel.INotifyPropertyChanged {

[Code] ....

I'm trying to access this method "RaceDaySimple[] raceDay" and display it on "WebForm1.aspx":

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebServiceClient.WebForm1" %>
<!DOCTYPE html>

[Code] ....

So on "WebForm1.aspx.cs" I'm trying to access the method "RaceDaySimple[] raceDay" and display it inside the div "test":

test.InnerHtml = pbs.fetchRaceDayCalendarSimple().raceDay;

But I'm getting the error:

Cannot implicitly convert 'WebServiceClient.InformationServiceReference.RaceDaySimple[]' to 'String'

So how do I acces this method proparly and display the content on "WebForm1.aspx" inside the div "test"?

View 1 Replies View Related







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