6 Replies - 31729 Views - Last Post: 14 December 2011 - 11:01 AM Rate Topic: -----

#1 njmiano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-February 08

Cannot resolve address of overloaded function

Post icon  Posted 13 April 2009 - 09:35 PM

I am having issues with a program I am writing for class.

I have created a class called transform, which seems to do everything it is supposed to do as long as I only initiate one instance of the class. If, in main() I try to initiate 2 variables of type Transform I am unable to compile the program with an error message "error: statement cannot resolve address of overloaded function"

I am posting just the main function and the header file. If anyone needs me tp post the definitions for the methods, let me know.

Here is main()
int main()
{
	   Transform a, b;
	  
	   a.printMatrix();
	   
	   a.Scale(2);
	   a.printMatrix();
	   
	   a.Rotate (6.28);
	   a.printMatrix();
	   
	   a.Translate(12, 88);
	   a.printMatrix();
	   
	   b.printMatrix; //This causes the error
	   return 0;
}
	



and the header file

#include<iostream>
/*#include "Point.h"*/
using namespace std;


class Transform {
	public:
	Transform();
	
	void Scale(float c);
	
	void Rotate(float theta);
	
	void Translate(float x, float y);
	
	void printMatrix();
	
	Transform operator* (const Transform &t);
	private:
	float mArray[3][3];
	
	
};






Thanks in advance for any help and advice.

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot resolve address of overloaded function

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Cannot resolve address of overloaded function

Posted 13 April 2009 - 09:37 PM

You're missing function parentheses:

b.printMatrix; //This causes the error

//should be
b.printMatrix();


This post has been edited by KYA: 13 April 2009 - 09:37 PM

Was This Post Helpful? 2
  • +
  • -

#3 njmiano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 26-February 08

Re: Cannot resolve address of overloaded function

Posted 13 April 2009 - 09:40 PM

Thanks, I feel a little stupid now.

By the way I have read quite a few of your tutorials on this site. Thanks for taking the time to do those. They have helped me a lot. Have a good day/evening.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Confused++*


Reputation:

Re: Cannot resolve address of overloaded function

Posted 08 March 2010 - 02:55 PM

I have the same error message for the final if statement in this program:
#include <iostream>
#include <cmath>
#include <vector>
#include "cavlib/constants.hh"
#include <cavlib/vec3.hh>

using cav::Vec3;

//this class sets up the elements of the wire.
class Wire{
  std::vector<Vec3> r_e; //the position of an element.
  Vec3 r_p; //the point the field is being calculated for.
  public:
  Wire(int, double, Vec3); //constructor.
  ~Wire(); //destructor.
  Vec3 field(){
	std::vector<Vec3> field_elements;
  	Vec3 total_field;
  	//loop puts the field for each element in successive members of field_elements, and adds to the total field.
  	for(int n = 0; n < (int) r_e.size(); n++){
    		Vec3 dl = r_e[n+1] - r_e[n];
    		Vec3 R = (r_p  - (r_e[n] + (dl/2)));//from midpoint of element.
    		double Rcubed =pow(R.len(),3);
    		field_elements.push_back((dl*R)/(4*C::pi*Rcubed));
    		total_field += field_elements[n];
  	}
  	return total_field;
	}
};

//constructor, assigns necessary values to variables used in object of type wire, here called circle.
Wire::Wire(int N, double R, Vec3 position){

  //loop defines positions of elements describing a circle centred on (0,0,0).
  for(int j = 0; j < N; j+=1){
      r_e.push_back(Vec3(0,R*cos(2*C::pi*j/N),R*sin(2*C::pi*j/N)));
  } 
  r_p = position;

}

Wire::~Wire(){
}

//this function calculates the theoretical magnitude of the field at on axis points - for use in plotting first graph.
double theoretical(std::vector<Vec3> axis_point, int p){
  double B = 1/(2*pow((1+pow(axis_point[p].x(),2)),1.5));
  return B;
}


int main()
{
  std::vector<Vec3> point; //vector of points in xy plane.

  //now fill point with positions, outer loop is y, innner is x, so scan along x axis then up y.
	for(double a = -1.0; a <= 1.01; a+=0.01){
		for(double i = -1.0; i <= 1.01; i+=0.01){
			point.push_back( Vec3(i,a,0) );
		}
	}

	for(int k = 0; k < (int) point.size(); k++){
		Wire circle(1000, 1, point[k]); //construct object of the wire class by setting up the wire elements and position- first element of point.
		std::cout<< point[k].x() <<" "<< point[k].y() <<" "<< circle.field().x() <<" "<< circle.field().y() <<" "<< circle.field().z() <<" "<< circle.field().len() << std::endl;
		if(point[k].x() >= 1)std::endl; //add break line after scanning through one value of y.
	}
    
}


The previous call point[k].x() happily compiles and prints out the x value of the vector, but the if statement is intended to insert line breaks after scanning across points of constant y so that a surface plot can be made. With braces included around std::endl; the error is the same.

thank you for looking at this!

This post has been edited by JackOfAllTrades: 08 March 2010 - 03:29 PM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE...[/code]

Was This Post Helpful? 0

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Cannot resolve address of overloaded function

Posted 08 March 2010 - 03:31 PM

You still need to provide the stream to which the endl will be added!
if(point[k].x() >= 1) std::cout << std::endl; //add break line after scanning through one value of y.

i.e., you're missing the std::cout <<.
Was This Post Helpful? 0
  • +
  • -

#6 yanike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-December 11

Re: Cannot resolve address of overloaded function

Posted 14 December 2011 - 10:47 AM

View PostKYA, on 13 April 2009 - 09:37 PM, said:

You're missing function parentheses:

b.printMatrix; //This causes the error

//should be
b.printMatrix();



I joined this site to plus one this and say thank you. Amazing how a silly overlooked error can cause problems.
Was This Post Helpful? 0
  • +
  • -

#7 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 650
  • View blog
  • Posts: 2,223
  • Joined: 31-December 10

Re: Cannot resolve address of overloaded function

Posted 14 December 2011 - 11:01 AM

I realize this post is old, but someone else resurrected it and I just want to add something. In the OP's header file, he/she has a "using directive", i.e. the "using namespace std;". This is never a good idea. The using directive brings all names in the "std" namespace into the global namespace. This would be ok if you put it in the implementation file, but not the header. Header files are included by other programs, etc., so the using directive will have unintended side-effects on any program that includes that header. This should never be the case, so just remember, NEVER put a using directive in a header file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1