473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Template Pointer Type....

Hello Folks...

Just going through the templates... found one good question worth sharing

C++ allows the syntax type

template <class T>
T * ptr;

can this ptr be used to point to types likes int variable or float variable

ex: int i =10;
ptr = &i;

If this can be done plz share the syntax of doing it...
Comments will be appreciated...
Sep 19 '08 #1
11 2888
MarkoKlacar
296 Expert 100+
Hi,

I'm not quite sure what you're looking for here...but anyways...
The *ptr can point out T-objects, the T object can be an int, float or Whatever just as long as you specify it when you use the template.

/MK
Sep 19 '08 #2
Hi,

I'm not quite sure what you're looking for here...but anyways...
The *ptr can point out T-objects, the T object can be an int, float or Whatever just as long as you specify it when you use the template.

/MK
Hello ....
Can you just give me the syntax of how to do that ...
i have created
template <class T>
T * ptr;

main()
{
int i =10;
//Here i want to assign the address of i to ptr & display value using ptr

float j = 20.23;
//here i want to assing the address of j to ptr & display value using ptr

return 0;
}
Sep 22 '08 #3
MarkoKlacar
296 Expert 100+
Hi,

Check out this link.

/MK
Sep 22 '08 #4
Hi,

Check out this link.

/MK
already went through this link ... didnt find anything related to this problem...
Sep 22 '08 #5
MarkoKlacar
296 Expert 100+
Hi,

I hope I understood your question correctly. What you're trying to do is declare a template<class>, och then point it out with a template<class> pointer.

Is that correct?

/MK
Sep 22 '08 #6
Hi,

I hope I understood your question correctly. What you're trying to do is declare a template<class>, och then point it out with a template<class> pointer.

Is that correct?

/MK
Hi ...

I want to assign the address of variable i to ptr(template type) and then display the value using ptr... any idea how to do that ??
Sep 22 '08 #7
Hi ...

I want to assign the address of variable i to ptr(template type) and then display the value using ptr... any idea how to do that ??
Hello ... are u there ??
Sep 22 '08 #8
MarkoKlacar
296 Expert 100+
Hi,

Not quite sure I'm afraid...I think you have to override some operator, don't quite remember...sorry.

/MK
Sep 22 '08 #9
Hi,

Not quite sure I'm afraid...I think you have to override some operator, don't quite remember...sorry.

/MK
ok let me know if u remember... thanx...
Sep 22 '08 #10
Sirmont
12
Posted by accident. Use below post.
Sep 23 '08 #11
Sirmont
12
C++ allows the syntax type

template <class T>
T * ptr;
NO... It doesn't. This is not a valid template definition. Are you trying to do this:

Expand|Select|Wrap|Line Numbers
  1. template<typename T>
  2. class MyClass
  3. {
  4.  T* m_Ptr;
  5. };
  6.  
If so, the syntax would be:

Expand|Select|Wrap|Line Numbers
  1. float i = 10;
  2. MyClass<float>* c;
  3. c.m_Ptr = &i;
  4.  
Sep 23 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Surya Kiran | last post by:
Hi all, I've written a function template. say template <class T> fn (T var) { ... } Is there any way, from within the function, can we check what type of argument we've passed on to the...
11
by: Marcin Kalicinski | last post by:
Hi, How to convert a type inside a template from pointer to type to type itself? struct S { }; template<class It> void f(It begin, It end) { // When called from g(), It::value_type is a...
4
by: firegun9 | last post by:
Hello everyone, here is my program: /////////////////////////////// #include <iostream> using namespace std; void multi(double* arrayPtr, int len){ for(int i=0; i<len; i++)...
3
by: case2005 | last post by:
Can anyone help with the following, I don't know if it's possible, but I'm certain there must be a standard way of dealing with this. I have the following: template<typename FooBar, typename...
4
by: Vijai Kalyan | last post by:
I was decomposing a task into different policies. Essentially, there is a general option obtained from a server and user options obtained from configuration variables. The two options are...
3
by: a | last post by:
Hi, I'm trying to create a helper class that will allow me to use a pointer or reference to a class without knowing if it is a pointer or reference. Conceptual example: //******************...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
3
by: .rhavin grobert | last post by:
guess you have the following: _________________________________________________ template <class T> class CQVector { public: // find an element, returns index or -1 if none is found int...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.